use of org.mifos.platform.questionnaire.ui.model.Question in project head by mifos.
the class QuestionFormTest method testAddCurrentQuestion.
@Test
public void testAddCurrentQuestion() {
QuestionForm questionForm = getQuestionForm(" Q1 ", "freeText", "choice1");
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(text, questionForm.getCurrentQuestion().getText());
assertNotSame(type, questionForm.getCurrentQuestion().getType());
assertThat(text, is("Q1"));
assertThat(type, is("freeText"));
assertThat(choices.size(), is(0));
}
use of org.mifos.platform.questionnaire.ui.model.Question in project head by mifos.
the class QuestionFormTest method testAddCurrentSingleSelectQuestion.
@Test
public void testAddCurrentSingleSelectQuestion() {
QuestionForm questionForm = getQuestionForm("title1", "singleSelect", "choice");
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(text, questionForm.getCurrentQuestion().getText());
assertNotSame(type, questionForm.getCurrentQuestion().getType());
assertThat(choices.get(0).getValue(), is("choice"));
assertThat(text, is("title1"));
assertThat(type, is("singleSelect"));
}
use of org.mifos.platform.questionnaire.ui.model.Question in project head by mifos.
the class QuestionControllerTest method testAddQuestionWhenTitleIsEditedToOneAlreadyInDB.
@Test
public void testAddQuestionWhenTitleIsEditedToOneAlreadyInDB() throws Exception {
Question currentQuestion = new Question();
QuestionDetail questionDetail = new QuestionDetail();
questionDetail.setText(TITLE);
currentQuestion.setQuestionDetail(questionDetail);
QuestionForm questionForm = new QuestionForm();
questionForm.setCurrentQuestion(currentQuestion);
questionForm.getCurrentQuestion().setText(TITLE + 1);
when(requestContext.getMessageContext()).thenReturn(messageContext);
when(questionnaireServiceFacade.isDuplicateQuestion(TITLE + 1)).thenReturn(true);
String result = questionController.addQuestion(questionForm, requestContext, false);
Assert.assertThat(questionForm.getQuestions().size(), is(0));
Assert.assertThat(result, is("failure"));
}
use of org.mifos.platform.questionnaire.ui.model.Question 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.Question 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"));
}
Aggregations