Search in sources :

Example 11 with Section

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

the class QuestionnaireMapperTest method assertQuestionGroupEntity.

private void assertQuestionGroupEntity(QuestionGroup questionGroup) {
    assertThat(questionGroup, is(notNullValue()));
    assertThat(questionGroup.getTitle(), is("QG1"));
    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().getQuestionText(), is("Ques1"));
    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().getQuestionText(), is("Ques2"));
    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("Ch1"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceOrder(), is(1));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceText(), is("Ch2"));
    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 12 with Section

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

the class QuestionnaireMapperTest method getSection.

private Section getSection(SectionQuestion sectionQuestion, int sectionId, String sectionName) {
    Section section = new Section();
    section.setId(sectionId);
    section.setName(sectionName);
    section.setSequenceNumber(0);
    section.setQuestions(asList(sectionQuestion));
    return section;
}
Also used : Section(org.mifos.platform.questionnaire.domain.Section)

Example 13 with Section

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

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

the class QuestionnaireServiceIntegrationTest method shouldDefineQuestionGroup.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldDefineQuestionGroup() throws SystemException {
    String title = TITLE + currentTimeMillis();
    QuestionDetail questionDetail1 = defineQuestion(title + 1, QuestionType.NUMERIC, true);
    QuestionDetail questionDetail2 = defineQuestion(title + 2, QuestionType.FREETEXT, true);
    SectionDetail section1 = getSectionWithQuestionId("S1", questionDetail1);
    SectionDetail section2 = getSectionWithQuestionId("S2", questionDetail2);
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", asList(section1, section2), true);
    assertNotNull(questionGroupDetail);
    Integer questionGroupId = questionGroupDetail.getId();
    assertNotNull(questionGroupId);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupId);
    assertNotNull(questionGroup);
    Assert.assertEquals(title, questionGroup.getTitle());
    Assert.assertEquals(QuestionGroupState.ACTIVE, questionGroup.getState());
    Assert.assertEquals(true, questionGroup.isEditable());
    List<Section> sections = questionGroup.getSections();
    Assert.assertEquals(2, sections.size());
    Assert.assertEquals("S1", sections.get(0).getName());
    Assert.assertEquals(title + 1, sections.get(0).getQuestions().get(0).getQuestion().getQuestionText());
    Assert.assertEquals("S2", sections.get(1).getName());
    Assert.assertEquals(title + 2, sections.get(1).getQuestions().get(0).getQuestion().getQuestionText());
    verifyCreationDate(questionGroup);
    verifyEventSources(questionGroup);
}
Also used : QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) Section(org.mifos.platform.questionnaire.domain.Section) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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