Search in sources :

Example 6 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm 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 7 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.

the class QuestionFormTest method testDuplicateQuestionInForm.

@Test
public void testDuplicateQuestionInForm() {
    QuestionForm questionForm = new QuestionForm();
    questionForm.setQuestions(asList(getQuestion(TITLE), getQuestion(TITLE + 1), getQuestion(TITLE + 2)));
    assertThat(questionForm.isDuplicateTitle(TITLE), is(true));
    assertThat(questionForm.isDuplicateTitle(" " + TITLE), is(true));
    assertThat(questionForm.isDuplicateTitle(TITLE.toUpperCase()), is(true));
    assertThat(questionForm.isDuplicateTitle(null), is(false));
    assertThat(questionForm.isDuplicateTitle(TITLE + "2"), is(true));
    assertThat(questionForm.isDuplicateTitle(TITLE + 3), is(false));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Test(org.junit.Test)

Example 8 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm 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 9 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm in project head by mifos.

the class QuestionFormTest method getQuestionForm.

private QuestionForm getQuestionForm(String title, String type, String choice) {
    QuestionForm questionForm = new QuestionForm();
    questionForm.getCurrentQuestion().setText(title);
    questionForm.getCurrentQuestion().setType(type);
    questionForm.getCurrentQuestion().setCurrentChoice(choice);
    questionForm.getCurrentQuestion().addAnswerChoice();
    questionForm.addCurrentQuestion();
    return questionForm;
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm)

Example 10 with QuestionForm

use of org.mifos.platform.questionnaire.ui.model.QuestionForm 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)

Aggregations

QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)20 Test (org.junit.Test)18 Question (org.mifos.platform.questionnaire.ui.model.Question)8 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)7 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)5 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)4 ArrayList (java.util.ArrayList)1 SystemException (org.mifos.framework.exceptions.SystemException)1