Search in sources :

Example 6 with MessageMatcher

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

the class QuestionGroupControllerTest method testSaveQuestionnaireFailureForNumericResponseWithoutBounds.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testSaveQuestionnaireFailureForNumericResponseWithoutBounds() {
    ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
    validationException.addChildException(new BadNumericResponseException("q1", null, 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.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 7 with MessageMatcher

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

the class QuestionGroupControllerTest method testAddQuestionForInvalidNumericBounds.

@Test
public void testAddQuestionForInvalidNumericBounds() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.setValidator(validator);
    questionGroupForm.getCurrentQuestion().setText(TITLE);
    questionGroupForm.getCurrentQuestion().setType("number");
    questionGroupForm.getCurrentQuestion().setNumericMin(100);
    questionGroupForm.getCurrentQuestion().setNumericMax(10);
    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(QuestionnaireConstants.INVALID_NUMERIC_BOUNDS)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 8 with MessageMatcher

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

the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleIsDuplicateInDB.

@Test
public void testAddQuestionForFailureWhenQuestionTitleIsDuplicateInDB() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText(TITLE);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE)).thenReturn(true);
    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("questionnaire.error.question.duplicate")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 9 with MessageMatcher

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

the class QuestionControllerTest method testCreateQuestionFailure.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testCreateQuestionFailure() throws Exception {
    QuestionForm questionForm = getQuestionForm(TITLE, "numeric");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    Mockito.doThrow(new SystemException("db.write.failure")).when(questionnaireServiceFacade).createQuestions(Matchers.<List<QuestionDetail>>anyObject());
    String result = questionController.createQuestions(questionForm, requestContext);
    Assert.assertThat(result, is("failure"));
    Mockito.verify(questionnaireServiceFacade).createQuestions(Matchers.<List<QuestionDetail>>anyObject());
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("db.write.failure")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) SystemException(org.mifos.framework.exceptions.SystemException) QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 10 with MessageMatcher

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

the class QuestionControllerTest method testAddQuestionForFailureWhenLessThanTwoChoicesAreGivenForMultiSelect.

@Test
public void testAddQuestionForFailureWhenLessThanTwoChoicesAreGivenForMultiSelect() throws Exception {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText("  " + TITLE + "    ");
    questionForm.getCurrentQuestion().setType("multiSelect");
    questionForm.getCurrentQuestion().setCurrentChoice("C1");
    questionForm.getCurrentQuestion().addAnswerChoice();
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionController.addQuestion(questionForm, requestContext, true);
    Assert.assertThat(result, is(notNullValue()));
    Assert.assertThat(result, is("failure"));
    Mockito.verify(requestContext).getMessageContext();
    Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.question.choices")));
}
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