Search in sources :

Example 31 with QuestionDetail

use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.

the class QuestionnaireValidatorTest method shouldNotThrowExceptionForNumericQuestionTypeWhenOnlyMaxBoundGiven.

@Test
public void shouldNotThrowExceptionForNumericQuestionTypeWhenOnlyMaxBoundGiven() {
    try {
        QuestionDetail questionDetail = new QuestionDetail("Title", QuestionType.NUMERIC);
        questionDetail.setNumericMax(-100);
        questionnaireValidator.validateForDefineQuestion(questionDetail);
    } catch (SystemException e) {
        fail("Should not have thrown the exception");
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 32 with QuestionDetail

use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.

the class QuestionTest method testAddSmartChoiceTag.

@Test
public void testAddSmartChoiceTag() {
    QuestionDetail questionDetail = new QuestionDetail();
    Question question = new Question(questionDetail);
    question.setCurrentSmartChoice("Choice1");
    question.addAnswerSmartChoice();
    question.setCurrentSmartChoice("Choice2");
    question.addAnswerSmartChoice();
    question.getCurrentSmartChoiceTags().set(1, "Tag1");
    question.addSmartChoiceTag(0);
    assertThat(questionDetail.getAnswerChoices().get(0).getTags().size(), is(0));
    assertThat(questionDetail.getAnswerChoices().get(1).getTags().size(), is(0));
    question.addSmartChoiceTag(1);
    assertThat(questionDetail.getAnswerChoices().get(1).getTags().get(0), is("Tag1"));
    assertThat(question.getCurrentSmartChoiceTags().get(1), is(""));
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 33 with QuestionDetail

use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.

the class QuestionTest method testAddAnswerChoice.

@Test
public void testAddAnswerChoice() {
    Question question = new Question(new QuestionDetail());
    question.setCurrentChoice("choice1");
    question.addAnswerChoice();
    question.setCurrentChoice("choice2");
    question.addAnswerChoice();
    question.setCurrentChoice("choice1");
    question.addAnswerChoice();
    question.setCurrentChoice("choice3");
    question.addAnswerChoice();
    assertThat(question.getChoices().size(), is(4));
    assertThat(question.getCurrentSmartChoiceTags().size(), is(4));
    assertEquals("choice1", question.getChoices().get(0).getValue());
    assertEquals("choice2", question.getChoices().get(1).getValue());
    assertEquals("choice1", question.getChoices().get(2).getValue());
    assertEquals("choice3", question.getChoices().get(3).getValue());
    assertEquals("choice1, choice2, choice1, choice3", question.getCommaSeparateChoices());
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 34 with QuestionDetail

use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.

the class QuestionTest method assertQuestion.

private void assertQuestion(String text, QuestionType questionType, String questionTypeString, List<String> choices) {
    QuestionDetail questionDetail = new QuestionDetail(123, text, questionType, true, true);
    List<ChoiceDto> choiceDtos = getChoiceDetails(choices);
    questionDetail.setAnswerChoices(choiceDtos);
    Question question = new Question(questionDetail);
    assertThat(question.getText(), is(text));
    assertThat(question.getType(), is(questionTypeString));
    assertEquals(question.getChoices(), choiceDtos);
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail)

Example 35 with QuestionDetail

use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.

the class QuestionTest method testAddSmartChoiceTagDoesnotAllowDuplicates.

@Test
public void testAddSmartChoiceTagDoesnotAllowDuplicates() {
    QuestionDetail questionDetail = new QuestionDetail();
    Question question = new Question(questionDetail);
    question.setCurrentSmartChoice("Choice1");
    question.addAnswerSmartChoice();
    question.getCurrentSmartChoiceTags().set(0, "Tag_1");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "Tag_1");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "Tag_2");
    question.addSmartChoiceTag(0);
    question.getCurrentSmartChoiceTags().set(0, "TAg_2");
    question.addSmartChoiceTag(0);
    assertThat(questionDetail.getAnswerChoices().get(0).getTags().size(), is(2));
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Aggregations

QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)72 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)55 Test (org.junit.Test)44 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)24 Question (org.mifos.platform.questionnaire.ui.model.Question)16 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)13 ArrayList (java.util.ArrayList)11 SystemException (org.mifos.framework.exceptions.SystemException)11 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)9 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)8 ValidationException (org.mifos.platform.validations.ValidationException)5 QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)4 Matchers.anyString (org.mockito.Matchers.anyString)4 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)3 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)3 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)3 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)2