Search in sources :

Example 16 with Question

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));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) Test(org.junit.Test)

Example 17 with Question

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"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) Test(org.junit.Test)

Example 18 with Question

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"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 19 with Question

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));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) ArrayList(java.util.ArrayList) Question(org.mifos.platform.questionnaire.ui.model.Question) Test(org.junit.Test)

Example 20 with Question

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"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Aggregations

Question (org.mifos.platform.questionnaire.ui.model.Question)23 Test (org.junit.Test)18 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)16 QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)8 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)2 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)2 ArrayList (java.util.ArrayList)1 SectionDetailForm (org.mifos.platform.questionnaire.ui.model.SectionDetailForm)1