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