Search in sources :

Example 11 with SectionDetail

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

the class SectionQuestionDaoIntegrationTest method shouldRetrieveSectionQuestionByQuestionIdSectionId.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldRetrieveSectionQuestionByQuestionIdSectionId() {
    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);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
    Integer questionId = questionGroup.getSections().get(1).getQuestions().get(1).getQuestion().getQuestionId();
    Integer sectionId = questionGroup.getSections().get(1).getId();
    List<SectionQuestion> sectionQuestions = sectionQuestionDao.retrieveFromQuestionIdSectionId(sectionId, questionId);
    assertThat(sectionQuestions, is(notNullValue()));
    assertThat(sectionQuestions.size(), is(1));
    assertThat(sectionQuestions.get(0).getQuestionText(), is(sectionDetail2.getQuestionDetail(1).getText()));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with SectionDetail

use of org.mifos.platform.questionnaire.service.SectionDetail 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 13 with SectionDetail

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

the class QuestionnaireMapperTest method getSectionDefinition.

private SectionDetail getSectionDefinition(String name, int questionId, String questionTitle) {
    SectionDetail section = new SectionDetail();
    section.setName(name);
    section.addQuestion(new SectionQuestionDetail(new QuestionDetail(questionId, questionTitle, QuestionType.FREETEXT, true, true), 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 14 with SectionDetail

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

the class QuestionGroupDaoIntegrationTest 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)

Example 15 with SectionDetail

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

Aggregations

SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)56 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)34 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)25 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)24 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)20 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)13 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)12 Transactional (org.springframework.transaction.annotation.Transactional)7 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)5 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)5 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)5 ValidationException (org.mifos.platform.validations.ValidationException)5 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)3 Section (org.mifos.platform.questionnaire.domain.Section)3 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)3 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)3 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)2 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)2