Search in sources :

Example 21 with MessageMatcher

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

the class QuestionGroupControllerTest method testSaveQuestionnaireFailureForNumericResponseGreaterThanMaxBound.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testSaveQuestionnaireFailureForNumericResponseGreaterThanMaxBound() {
    ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
    validationException.addChildException(new BadNumericResponseException("q1", null, 100));
    doThrow(validationException).when(questionnaireServiceFacade).saveResponses(Mockito.<QuestionGroupDetails>any());
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionGroupController.saveQuestionnaire(getQuestionGroupDetails(), 1, requestContext);
    assertThat(result, is("failure"));
    verify(requestContext, times(1)).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.invalid.numeric.max.response")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) BadNumericResponseException(org.mifos.platform.questionnaire.exceptions.BadNumericResponseException) ValidationException(org.mifos.platform.validations.ValidationException) Test(org.junit.Test)

Example 22 with MessageMatcher

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

the class QuestionGroupControllerTest method testCreateQuestionGroupForFailureWhenQuestionGroupTitleNotProvided.

@Test
public void testCreateQuestionGroupForFailureWhenQuestionGroupTitleNotProvided() throws Exception {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(null, "Create.Client", "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.questionGroup.title.empty")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 23 with MessageMatcher

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

the class QuestionGroupControllerTest method testCreateQuestionGroupFailureWhenSectionsNotPresent.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testCreateQuestionGroupFailureWhenSectionsNotPresent() throws Exception {
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client");
    String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true);
    assertThat(result, Is.is("failure"));
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.section.atLeastOne")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 24 with MessageMatcher

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

the class QuestionGroupControllerTest method testSaveQuestionnaireFailureForNumericResponseLessThanMinBound.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testSaveQuestionnaireFailureForNumericResponseLessThanMinBound() {
    ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
    validationException.addChildException(new BadNumericResponseException("q1", 10, null));
    doThrow(validationException).when(questionnaireServiceFacade).saveResponses(Mockito.<QuestionGroupDetails>any());
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionGroupController.saveQuestionnaire(getQuestionGroupDetails(), 1, requestContext);
    assertThat(result, is("failure"));
    verify(requestContext, times(1)).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.invalid.numeric.min.response")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) BadNumericResponseException(org.mifos.platform.questionnaire.exceptions.BadNumericResponseException) ValidationException(org.mifos.platform.validations.ValidationException) Test(org.junit.Test)

Example 25 with MessageMatcher

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

the class QuestionGroupControllerTest method testAddQuestionForDuplicateTitle.

@Test
public void testAddQuestionForDuplicateTitle() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.setValidator(validator);
    questionGroupForm.getCurrentQuestion().setText(TITLE);
    questionGroupForm.getCurrentQuestion().setType("freeText");
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE)).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("questionnaire.error.question.duplicate")));
}
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