use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.
the class QuestionFormTest method testAddCurrentMultiSelectQuestion.
@Test
public void testAddCurrentMultiSelectQuestion() {
QuestionForm questionForm = getQuestionForm("title", "multiSelect", "choice2");
List<Question> questionList = questionForm.getQuestions();
assertThat(questionList.size(), is(1));
String text = questionList.get(0).getText();
String type = questionList.get(0).getType();
List<ChoiceDto> choices = questionList.get(0).getChoices();
assertNotSame(type, questionForm.getCurrentQuestion().getType());
assertNotSame(text, questionForm.getCurrentQuestion().getText());
assertThat(type, is("multiSelect"));
assertThat(text, is("title"));
assertThat(choices.get(0).getValue(), is("choice2"));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionForm 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.questionnaire.ui.model.QuestionForm 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.questionnaire.ui.model.QuestionForm 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")));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionForm 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)));
}
Aggregations