Search in sources :

Example 6 with Section

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

the class QuestionnaireServiceIntegrationTest method assertQuestionGroup.

private void assertQuestionGroup(QuestionGroup questionGroup, String questionGroupTitle, String firstQuestionTitle, String secondQuestionTitle) {
    assertThat(questionGroup, is(notNullValue()));
    assertThat(questionGroup.getTitle(), is(questionGroupTitle));
    Set<EventSourceEntity> eventSources = questionGroup.getEventSources();
    assertThat(eventSources, is(notNullValue()));
    assertThat(eventSources.size(), is(1));
    EventSourceEntity eventSourceEntity = eventSources.toArray(new EventSourceEntity[eventSources.size()])[0];
    assertThat(eventSourceEntity.getEvent().getName(), is("Create"));
    assertThat(eventSourceEntity.getSource().getEntityType(), is("Client"));
    assertThat(questionGroup.getState(), is(QuestionGroupState.ACTIVE));
    List<Section> sections = questionGroup.getSections();
    assertThat(sections, is(notNullValue()));
    assertThat(sections.size(), is(1));
    Section section = sections.get(0);
    assertThat(section.getName(), is("Sec1"));
    List<SectionQuestion> questions = section.getQuestions();
    assertThat(questions, is(notNullValue()));
    assertThat(questions.size(), is(2));
    SectionQuestion sectionQuestion1 = questions.get(0);
    assertThat(sectionQuestion1.getSequenceNumber(), is(1));
    assertThat(sectionQuestion1.getSection(), is(notNullValue()));
    assertThat(sectionQuestion1.getSection().getName(), is("Sec1"));
    assertThat(sectionQuestion1.getSection().getSequenceNumber(), is(1));
    assertThat(sectionQuestion1.getQuestion(), is(notNullValue()));
    assertThat(sectionQuestion1.getQuestion().getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
    assertThat(sectionQuestion1.getQuestion().getQuestionText(), is(firstQuestionTitle));
    assertThat(sectionQuestion1.getQuestion().getAnswerTypeAsEnum(), is(AnswerType.FREETEXT));
    SectionQuestion sectionQuestion2 = questions.get(1);
    assertThat(sectionQuestion2.getSequenceNumber(), is(2));
    assertThat(sectionQuestion2.getSection(), is(notNullValue()));
    assertThat(sectionQuestion2.getSection().getName(), is("Sec1"));
    assertThat(sectionQuestion2.getSection().getSequenceNumber(), is(1));
    assertThat(sectionQuestion2.getQuestion(), is(notNullValue()));
    assertThat(sectionQuestion2.getQuestion().getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
    assertThat(sectionQuestion2.getQuestion().getQuestionText(), is(secondQuestionTitle));
    assertThat(sectionQuestion2.getQuestion().getAnswerTypeAsEnum(), is(AnswerType.SINGLESELECT));
    assertThat(sectionQuestion2.getQuestion().getChoices(), is(notNullValue()));
    assertThat(sectionQuestion2.getQuestion().getChoices().size(), is(3));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceText(), is("Ch2"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceOrder(), is(1));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceText(), is("Ch1"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceOrder(), is(2));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(2).getChoiceText(), is("Ch3"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(2).getChoiceOrder(), is(3));
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) Section(org.mifos.platform.questionnaire.domain.Section)

Example 7 with Section

use of org.mifos.platform.questionnaire.domain.Section 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 8 with Section

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

the class QuestionGroupDaoIntegrationTest method shouldRetrieveSectionQuestionIdByQuestionGroupNameSectionNameQuestionId.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldRetrieveSectionQuestionIdByQuestionGroupNameSectionNameQuestionId() {
    String title = "QG1" + currentTimeMillis();
    SectionDetail sectionDetail1 = getSection("S1");
    SectionDetail sectionDetail2 = getSection("S2");
    List<SectionDetail> details = asList(sectionDetail1, sectionDetail2);
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    List<Section> sections = questionGroupDao.retrieveSectionByNameAndQuestionGroupId("S2", questionGroupDetail.getId());
    assertThat(sections, is(notNullValue()));
    assertThat(sections.size(), is(1));
    Section section2 = sections.get(0);
    assertThat(section2.getName(), is("S2"));
    List<SectionQuestion> sections2Questions = section2.getQuestions();
    assertThat(sections2Questions, is(notNullValue()));
    assertThat(sections2Questions.size(), is(3));
    assertThat(sections2Questions.get(0).getQuestionText(), is(sectionDetail2.getQuestionDetail(0).getText()));
    assertThat(sections2Questions.get(1).getQuestionText(), is(sectionDetail2.getQuestionDetail(1).getText()));
    assertThat(sections2Questions.get(2).getQuestionText(), is(sectionDetail2.getQuestionDetail(2).getText()));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Section(org.mifos.platform.questionnaire.domain.Section) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Section

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

the class QuestionnaireMapperImpl method getSection.

private Section getSection(QuestionGroupDetail questionGroupDetail, SectionDetail sectionDetail) {
    String sectionName = sectionDetail.getName();
    Section section = new Section(sectionName);
    if (!questionGroupDetail.isNewQuestionGroup()) {
        List<Section> sections = questionGroupDao.retrieveSectionByNameAndQuestionGroupId(sectionName, questionGroupDetail.getId());
        if (isNotEmpty(sections)) {
            section = sections.get(0);
        }
    }
    return section;
}
Also used : Section(org.mifos.platform.questionnaire.domain.Section)

Example 10 with Section

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupDefinitionToExistingQuestionGroup.

@Test
public void shouldMapQuestionGroupDefinitionToExistingQuestionGroup() {
    when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
    when(questionDao.getDetails(12)).thenReturn(new QuestionEntity());
    Section section = getSection("S1");
    when(questionGroupDao.getDetails(123)).thenReturn(getQuestionGroup(123, "QG Title", section));
    when(questionGroupDao.retrieveSectionByNameAndQuestionGroupId("S1", 123)).thenReturn(asList(section));
    EventSourceDto eventSourceDto = getEventSource("Create", "Client");
    List<SectionDetail> sectionDetails = asList(getSectionDefinition("S1", 12, TITLE), getSectionDefinition("S2", 0, TITLE));
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(123, 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);
    verify(questionGroupDao, times(1)).getDetails(123);
    verify(questionGroupDao, times(1)).retrieveSectionByNameAndQuestionGroupId("S1", 123);
}
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) Section(org.mifos.platform.questionnaire.domain.Section) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Aggregations

Section (org.mifos.platform.questionnaire.domain.Section)14 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)7 Test (org.junit.Test)4 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)3 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)3 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)3 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)3 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)1 Matchers.anyString (org.mockito.Matchers.anyString)1