Search in sources :

Example 1 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireMapperTest method getSection.

private Section getSection(String sectionName, int questionId) {
    Section section = new Section(sectionName);
    SectionQuestion sectionQuestion = new SectionQuestion();
    QuestionEntity question = new QuestionEntity();
    question.setQuestionId(questionId);
    question.setQuestionText(sectionName);
    question.setAnswerType(AnswerType.DATE);
    question.setChoices(new LinkedList<QuestionChoiceEntity>());
    sectionQuestion.setQuestion(question);
    section.setQuestions(asList(sectionQuestion));
    return section;
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) Section(org.mifos.platform.questionnaire.domain.Section)

Example 2 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireServiceIntegrationTest method shouldDefineSingleSelectQuestion.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldDefineSingleSelectQuestion() throws SystemException {
    String questionTitle = TITLE + currentTimeMillis();
    QuestionDetail questionDetail = defineQuestion(questionTitle, QuestionType.SINGLE_SELECT, asList("choice1", "choice2"));
    assertNotNull(questionDetail);
    Integer questionId = questionDetail.getId();
    assertNotNull(questionId);
    QuestionEntity questionEntity = questionDao.getDetails(questionId);
    assertNotNull(questionEntity);
    Assert.assertEquals(questionTitle, questionEntity.getQuestionText());
    Assert.assertEquals(AnswerType.SINGLESELECT, questionEntity.getAnswerTypeAsEnum());
    assertThat(questionEntity.getChoices(), new QuestionChoicesMatcher(asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2"))));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireServiceIntegrationTest method getChoice.

private QuestionChoiceEntity getChoice(String choiceText, int choiceOrder, String... tagTexts) {
    QuestionChoiceEntity questionChoiceEntity = new QuestionChoiceEntity();
    questionChoiceEntity.setChoiceText(choiceText);
    questionChoiceEntity.setChoiceOrder(choiceOrder);
    Set<ChoiceTagEntity> tags = new HashSet<ChoiceTagEntity>();
    for (String tagText : tagTexts) {
        tags.add(getTag(tagText));
    }
    questionChoiceEntity.setTags(tags);
    return questionChoiceEntity;
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) ChoiceTagEntity(org.mifos.platform.questionnaire.domain.ChoiceTagEntity) HashSet(java.util.HashSet)

Example 4 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireServiceIntegrationTest method shouldDefineMultiSelectQuestion.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldDefineMultiSelectQuestion() throws SystemException {
    String questionTitle = TITLE + currentTimeMillis();
    QuestionDetail questionDetail = defineQuestion(questionTitle, QuestionType.MULTI_SELECT, asList("choice1", "choice2"));
    Assert.assertNotNull(questionDetail);
    Integer questionId = questionDetail.getId();
    assertNotNull(questionId);
    QuestionEntity questionEntity = questionDao.getDetails(questionId);
    assertNotNull(questionEntity);
    Assert.assertEquals(questionTitle, questionEntity.getQuestionText());
    Assert.assertEquals(AnswerType.MULTISELECT, questionEntity.getAnswerTypeAsEnum());
    assertThat(questionEntity.getChoices(), new QuestionChoicesMatcher(asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2"))));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireMapperTest method getSectionWithOneMultiSelectQuestion.

private Section getSectionWithOneMultiSelectQuestion(int sectionQuestionId, String sectionName, String questionName, String... choices) {
    Section section = new Section(sectionName);
    List<SectionQuestion> sectionQuestions = new ArrayList<SectionQuestion>();
    SectionQuestion sectionQuestion = new SectionQuestion();
    sectionQuestion.setId(sectionQuestionId);
    sectionQuestion.setSection(section);
    QuestionEntity questionEntity = new QuestionEntity();
    questionEntity.setQuestionText(questionName);
    questionEntity.setAnswerType(AnswerType.MULTISELECT);
    LinkedList<QuestionChoiceEntity> questionChoiceEntities = new LinkedList<QuestionChoiceEntity>();
    for (String choice : choices) {
        QuestionChoiceEntity questionChoiceEntity = new QuestionChoiceEntity();
        questionChoiceEntity.setChoiceText(choice);
        questionChoiceEntities.add(questionChoiceEntity);
    }
    questionEntity.setChoices(questionChoiceEntities);
    sectionQuestion.setQuestion(questionEntity);
    sectionQuestions.add(sectionQuestion);
    section.setQuestions(sectionQuestions);
    return section;
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Section(org.mifos.platform.questionnaire.domain.Section) LinkedList(java.util.LinkedList)

Aggregations

QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)13 Test (org.junit.Test)8 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)7 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)4 ChoiceTagEntity (org.mifos.platform.questionnaire.domain.ChoiceTagEntity)3 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)3 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)3 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)3 ValidationException (org.mifos.platform.validations.ValidationException)3 Arrays.asList (java.util.Arrays.asList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Section (org.mifos.platform.questionnaire.domain.Section)2 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)2 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1