Search in sources :

Example 36 with SectionQuestionDetail

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupsToQuestionGroupDetails.

@Test
public void shouldMapQuestionGroupsToQuestionGroupDetails() {
    int countOfQuestions = 10;
    List<QuestionGroup> questionGroups = new ArrayList<QuestionGroup>();
    for (int i = 0; i < countOfQuestions; i++) {
        questionGroups.add(getQuestionGroup(1991, TITLE + i, "View", "Loan", QuestionGroupState.ACTIVE, true, getSection(SECTION + i), getSection(SECTION + (i + 1))));
    }
    List<QuestionGroupDetail> questionGroupDetails = questionnaireMapper.mapToQuestionGroupDetails(questionGroups);
    assertThat(questionGroupDetails, is(notNullValue()));
    for (int i = 0; i < countOfQuestions; i++) {
        QuestionGroupDetail questionGroupDetail = questionGroupDetails.get(i);
        assertThat(questionGroupDetail.getTitle(), is(TITLE + i));
        SectionDetail sectionDefinition1 = questionGroupDetail.getSectionDetails().get(0);
        assertThat(sectionDefinition1.getName(), is(SECTION + i));
        List<SectionQuestionDetail> questionDetails1 = sectionDefinition1.getQuestions();
        assertThat(questionDetails1.size(), is(1));
        assertThat(questionDetails1.get(0).getText(), is(SECTION + i));
        assertThat(questionDetails1.get(0).getQuestionType(), is(QuestionType.DATE));
        SectionDetail sectionDefinition2 = questionGroupDetail.getSectionDetails().get(1);
        assertThat(sectionDefinition2.getName(), is(SECTION + (i + 1)));
        List<SectionQuestionDetail> questionDetails2 = sectionDefinition2.getQuestions();
        assertThat(questionDetails2.size(), is(1));
        assertThat(questionDetails2.get(0).getText(), is(SECTION + (i + 1)));
        assertThat(questionDetails2.get(0).getQuestionType(), is(QuestionType.DATE));
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test)

Example 37 with SectionQuestionDetail

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupToExistingQuestionGroupWhileAddingQuestionToOldSection.

@Test
public void shouldMapQuestionGroupToExistingQuestionGroupWhileAddingQuestionToOldSection() {
    Integer questionGroupId = 123;
    EventSourceDto eventSourceDto = getEventSource("Create", "Client");
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setName("Misc");
    SectionQuestionDetail sectionQuestionDetail1 = getSectionQuestionDetail(111, 999, "Ques1");
    SectionQuestionDetail sectionQuestionDetail2 = getSectionQuestionDetail(0, 0, "Ques2");
    sectionDetail.setQuestionDetails(asList(sectionQuestionDetail1, sectionQuestionDetail2));
    List<SectionDetail> sectionDetails = asList(sectionDetail);
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(questionGroupId, TITLE, Arrays.asList(eventSourceDto), sectionDetails, true, true);
    SectionQuestion sectionQuestion = getSectionQuestion(getQuestionEntity(999, "Ques1"), 333);
    Section section = getSection(sectionQuestion, 222, "Misc");
    when(questionGroupDao.retrieveSectionByNameAndQuestionGroupId("Misc", 123)).thenReturn(asList(section));
    when(questionGroupDao.getDetails(questionGroupId)).thenReturn(getQuestionGroup(questionGroupId, "QG Title", section));
    when(sectionQuestionDao.retrieveFromQuestionIdSectionId(222, 999)).thenReturn(asList(sectionQuestion));
    when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
    QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(questionGroupDetail);
    assertQuestionGroupForExistingQuestion(questionGroup, QuestionGroupState.ACTIVE);
    verify(questionGroupDao).retrieveSectionByNameAndQuestionGroupId("Misc", 123);
    verify(questionGroupDao).getDetails(questionGroupId);
    verify(sectionQuestionDao).retrieveFromQuestionIdSectionId(222, 999);
    verify(eventSourceDao).retrieveByEventAndSource(anyString(), anyString());
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) 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)

Example 38 with SectionQuestionDetail

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

the class QuestionnaireServiceTest method getSectionDetailWithQuestions.

private SectionDetail getSectionDetailWithQuestions(String name, List<QuestionDetail> questionDetails, String value, boolean mandatory) {
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setName(name);
    List<SectionQuestionDetail> sectionQuestionDetails = new ArrayList<SectionQuestionDetail>();
    for (QuestionDetail questionDetail : questionDetails) {
        SectionQuestionDetail sectionQuestionDetail = new SectionQuestionDetail(questionDetail, mandatory);
        sectionQuestionDetail.setValue(value);
        sectionQuestionDetails.add(sectionQuestionDetail);
    }
    sectionDetail.setQuestionDetails(sectionQuestionDetails);
    return sectionDetail;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 39 with SectionQuestionDetail

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

the class QuestionGroupInstanceDaoIntegrationTest method getSection.

private SectionDetail getSection(String name) throws SystemException {
    SectionDetail section = new SectionDetail();
    section.setName(name);
    String questionTitle = "Question" + name + currentTimeMillis();
    QuestionDetail questionDetail = defineQuestion(questionTitle, QuestionType.NUMERIC);
    section.addQuestion(new SectionQuestionDetail(questionDetail, true));
    return section;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 40 with SectionQuestionDetail

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

the class SectionQuestionDaoIntegrationTest method getSection.

private SectionDetail getSection(String name) throws SystemException {
    SectionDetail section = new SectionDetail();
    section.setName(name);
    section.addQuestion(new SectionQuestionDetail(defineQuestion("Question1" + name + currentTimeMillis(), QuestionType.NUMERIC), true));
    section.addQuestion(new SectionQuestionDetail(defineQuestion("Question2" + name + currentTimeMillis(), QuestionType.DATE), true));
    section.addQuestion(new SectionQuestionDetail(defineQuestion("Question3" + name + currentTimeMillis(), QuestionType.FREETEXT), false));
    return section;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

Aggregations

SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)44 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)25 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)21 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)7 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)6 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)5 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)3 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)2 QuestionLinkDetail (org.mifos.platform.questionnaire.service.QuestionLinkDetail)2 SectionLinkDetail (org.mifos.platform.questionnaire.service.SectionLinkDetail)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 HashSet (java.util.HashSet)1 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)1 AuditLog (org.mifos.framework.components.audit.business.AuditLog)1 AuditLogRecord (org.mifos.framework.components.audit.business.AuditLogRecord)1 ServiceException (org.mifos.framework.exceptions.ServiceException)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 QuestionGroupInstanceDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionGroupInstanceDtoBuilder)1