use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.
the class QuestionControllerTest method testAddQuestionForSuccessWhenTwoChoicesAreGivenForSigleSelect.
@Test
public void testAddQuestionForSuccessWhenTwoChoicesAreGivenForSigleSelect() throws Exception {
QuestionForm questionForm = new QuestionForm();
questionForm.getCurrentQuestion().setText(" " + TITLE + " ");
questionForm.getCurrentQuestion().setType("singleSelect");
questionForm.getCurrentQuestion().setCurrentChoice("C1");
questionForm.getCurrentQuestion().addAnswerChoice();
questionForm.getCurrentQuestion().setCurrentChoice("C2");
questionForm.getCurrentQuestion().addAnswerChoice();
when(requestContext.getMessageContext()).thenReturn(messageContext);
String result = questionController.addQuestion(questionForm, requestContext, true);
Assert.assertThat(result, is(notNullValue()));
Assert.assertThat(result, is("success"));
Assert.assertThat(questionForm.getQuestions().size(), is(1));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.
the class QuestionControllerTest method testRemoveQuestion.
@Test
public void testRemoveQuestion() {
QuestionForm questionForm = new QuestionForm();
ArrayList<Question> questions = new ArrayList<Question>();
questionForm.setQuestions(questions);
String title = "title";
questions.add(getQuestion("1", title, "freeText"));
questionController.removeQuestion(questionForm, "");
questionController.removeQuestion(questionForm, "junk");
Assert.assertThat(questionForm.getQuestions().size(), is(1));
questionController.removeQuestion(questionForm, title);
Assert.assertThat(questionForm.getQuestions().size(), is(0));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.
the class QuestionControllerTest method testAddQuestionForFailureWhenQuestionTitleProvidedWithAllBlanks.
@Test
public void testAddQuestionForFailureWhenQuestionTitleProvidedWithAllBlanks() throws Exception {
QuestionForm qform = new QuestionForm();
qform.setValidator(validator);
qform.getCurrentQuestion().setText(" ");
qform.getCurrentQuestion().setType("freeText");
when(requestContext.getMessageContext()).thenReturn(messageContext);
when(messageContext.hasErrorMessages()).thenReturn(true);
String result = questionController.addQuestion(qform, requestContext, true);
Assert.assertThat(qform.getQuestions().size(), is(0));
Assert.assertThat(result, is(notNullValue()));
Assert.assertThat(result, is("failure"));
Mockito.verify(requestContext).getMessageContext();
// TODO: Assert for message code content
Mockito.verify(messageContext).addMessage(argThat(new MessageMatcher("Pattern.QuestionForm.currentQuestion.text")));
//verify(messageContext).addMessage(argThat(new MessageMatcher("NotNull.QuestionForm.currentQuestion.type")));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.
the class QuestionControllerTest method testAddQuestionWhenTitleIsEdited.
@Test
public void testAddQuestionWhenTitleIsEdited() throws Exception {
Question currentQuestion = new Question();
QuestionDetail questionDetail = new QuestionDetail();
questionDetail.setText(TITLE);
questionDetail.setType(QuestionType.SINGLE_SELECT);
questionDetail.setAnswerChoices(new ArrayList<ChoiceDto>(Arrays.asList(new ChoiceDto("choice1"), new ChoiceDto("choice2"))));
currentQuestion.setQuestionDetail(questionDetail);
currentQuestion.setCurrentChoice("choice3");
currentQuestion.addAnswerChoice();
QuestionForm questionForm = new QuestionForm();
questionForm.setCurrentQuestion(currentQuestion);
questionForm.getCurrentQuestion().setText(TITLE + 1);
when(requestContext.getMessageContext()).thenReturn(messageContext);
when(questionnaireServiceFacade.isDuplicateQuestion(TITLE + 1)).thenReturn(false);
String result = questionController.addQuestion(questionForm, requestContext, false);
Assert.assertThat(questionForm.getQuestions().size(), is(1));
Assert.assertThat(questionForm.getQuestions().get(0).getInitialNumberOfChoices(), is(2));
Assert.assertThat(questionForm.getQuestions().get(0).getChoices().size(), is(3));
Assert.assertThat(result, is("success"));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.
the class QuestionControllerTest method getQuestionForm.
private QuestionForm getQuestionForm(String title, String type) {
QuestionForm questionForm = new QuestionForm();
questionForm.getCurrentQuestion().setText(title);
questionForm.getCurrentQuestion().setType(type);
return questionForm;
}
Aggregations