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")));
}
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)));
}
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")));
}
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")));
}
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")));
}
Aggregations