Search in sources :

Example 11 with QuestionEntity

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupDefinitionToQuestionGroup.

@Test
public void shouldMapQuestionGroupDefinitionToQuestionGroup() {
    when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
    when(questionDao.getDetails(12)).thenReturn(new QuestionEntity());
    EventSourceDto eventSourceDto = getEventSource("Create", "Client");
    List<SectionDetail> sectionDetails = asList(getSectionDefinition("S1", 12, TITLE), getSectionDefinition("S2", 0, TITLE));
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(0, TITLE, Arrays.asList(eventSourceDto), sectionDetails, true);
    questionGroupDetail.setActive(false);
    QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(questionGroupDetail);
    assertQuestionGroup(questionGroup, QuestionGroupState.INACTIVE);
    assertThat(questionGroup.isEditable(), is(true));
    verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
    verify(questionDao, times(1)).getDetails(12);
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 12 with QuestionEntity

use of org.mifos.platform.questionnaire.domain.QuestionEntity 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)

Example 13 with QuestionEntity

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

the class QuestionnaireMapperImpl method mapToQuestion.

@Override
public QuestionEntity mapToQuestion(QuestionDetail questionDetail) {
    QuestionEntity question = getQuestion(questionDetail);
    question.setQuestionId(questionDetail.getId() > 0 ? questionDetail.getId() : 0);
    question.setNickname(questionDetail.getNickname());
    question.setQuestionText(questionDetail.getText());
    question.setAnswerType(mapToAnswerType(questionDetail.getType()));
    question.setChoices(mapToChoices(questionDetail.getAnswerChoices()));
    question.setQuestionState(QuestionState.getQuestionStateEnum(questionDetail.isActive(), questionDetail.isEditable()));
    mapBoundsForNumericQuestionDetail(questionDetail, question);
    return question;
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity)

Example 14 with QuestionEntity

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

the class QuestionnaireValidatorForDtoTest method getQuestionEntity.

private QuestionEntity getQuestionEntity(String questionTitle, AnswerType answerType, List<QuestionChoiceEntity> choices) {
    QuestionEntity questionEntity = new QuestionEntity();
    questionEntity.setQuestionText(questionTitle);
    questionEntity.setAnswerType(answerType);
    questionEntity.setChoices(choices);
    return questionEntity;
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity)

Example 15 with QuestionEntity

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

the class QuestionnaireMapperTest method shouldMapQuestionToQuestionDetail.

@Test
public void shouldMapQuestionToQuestionDetail() {
    QuestionEntity question = getQuestion(TITLE, AnswerType.FREETEXT);
    question.setQuestionState(QuestionState.INACTIVE);
    QuestionDetail questionDetail = questionnaireMapper.mapToQuestionDetail(question);
    assertQuestionDetail(questionDetail, TITLE, QuestionType.FREETEXT);
    assertThat(questionDetail.isActive(), is(false));
    question = getQuestion(TITLE, AnswerType.MULTISELECT, asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2")));
    question.setQuestionState(QuestionState.ACTIVE);
    questionDetail = questionnaireMapper.mapToQuestionDetail(question);
    assertQuestionDetail(questionDetail, TITLE, QuestionType.MULTI_SELECT, asList("choice1", "choice2"));
    assertThat(questionDetail.isActive(), is(true));
    question = getQuestion(TITLE, AnswerType.NUMBER);
    question.setNumericMin(10);
    question.setNumericMax(100);
    questionDetail = questionnaireMapper.mapToQuestionDetail(question);
    assertQuestionDetail(questionDetail, TITLE, QuestionType.NUMERIC);
    assertThat(questionDetail.getNumericMin(), is(10));
    assertThat(questionDetail.getNumericMax(), is(100));
    assertThat(questionDetail.isActive(), is(true));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Aggregations

QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)25 Test (org.junit.Test)16 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)9 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)7 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)7 Transactional (org.springframework.transaction.annotation.Transactional)7 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)5 Section (org.mifos.platform.questionnaire.domain.Section)3 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)3 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)3 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)2 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)1 QuestionType (org.mifos.platform.questionnaire.service.QuestionType)1