Search in sources :

Example 26 with QuestionGroupDetail

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

the class QuestionnaireServiceTest method shouldGetAllQuestionGroupsByEventSource.

@Test
public void shouldGetAllQuestionGroupsByEventSource() throws SystemException {
    List<QuestionGroup> questionGroups = asList(getQuestionGroup(1, "Title1", "View", "Loan", QuestionGroupState.ACTIVE, true, getSections("Section1")), getQuestionGroup(2, "Title2", "View", "Loan", QuestionGroupState.ACTIVE, true, getSections("Section2")));
    when(questionGroupDao.retrieveQuestionGroupsByEventSource("Create", "Client")).thenReturn(questionGroups);
    List<QuestionGroupDetail> questionGroupDetails = questionnaireService.getQuestionGroups(new EventSourceDto("Create", "Client", "Create.Client"));
    assertThat(questionGroupDetails, is(notNullValue()));
    assertThat(questionGroupDetails.size(), is(2));
    assertThat(questionGroupDetails.get(0).getTitle(), is("Title1"));
    assertThat(questionGroupDetails.get(1).getTitle(), is("Title2"));
    verify(questionnaireValidator, times(1)).validateForEventSource(any(EventSourceDto.class));
    verify(questionGroupDao, times(1)).retrieveQuestionGroupsByEventSource("Create", "Client");
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 27 with QuestionGroupDetail

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

the class QuestionnaireServiceTest method shouldGetAllQuestionGroupsByEventSourceAndEntityId.

@Test
public void shouldGetAllQuestionGroupsByEventSourceAndEntityId() {
    QuestionGroup questionGroup1 = getQuestionGroup(1, "Title1", "View", "Loan", QuestionGroupState.ACTIVE, true, asList(getSectionWithQuestions(222, "Section1", "Question1", "Question2")));
    QuestionGroup questionGroup2 = getQuestionGroup(2, "Title2", "View", "Loan", QuestionGroupState.ACTIVE, true, asList(getSectionWithQuestions(222, "Section2", "Question2"), getSectionWithQuestions(222, "SectionN", "q1", "q2", "q3", "q4")));
    QuestionGroup questionGroup3 = getQuestionGroup(3, "Title3", "View", "Loan", QuestionGroupState.ACTIVE, true, asList(getSectionWithOneMultiSelectQuestion(222, "Section3", "Question3", "Choice1", "Choice2", "Choice3", "Choice4")));
    List<QuestionGroup> questionGroups = asList(questionGroup1, questionGroup2, questionGroup3);
    when(questionGroupDao.retrieveQuestionGroupsByEventSource("Create", "Client")).thenReturn(questionGroups);
    List<QuestionGroupDetail> questionGroupDetails = questionnaireService.getQuestionGroups(new EventSourceDto("Create", "Client", "Create.Client"));
    assertThat(questionGroupDetails, is(notNullValue()));
    assertThat(questionGroupDetails.size(), is(3));
    assertThat(questionGroupDetails.get(0).getSectionDetails().size(), is(1));
    assertThat(questionGroupDetails.get(1).getSectionDetails().size(), is(1));
    assertThat(questionGroupDetails.get(1).getSectionDetails().get(0).getName(), is("SectionN"));
    assertThat(questionGroupDetails.get(1).getSectionDetails().get(0).getQuestions().size(), is(2));
    assertThat(questionGroupDetails.get(1).getSectionDetails().get(0).getQuestions().get(0).getText(), is("q2"));
    assertThat(questionGroupDetails.get(1).getSectionDetails().get(0).getQuestions().get(1).getText(), is("q4"));
    assertThat(questionGroupDetails.get(2).getSectionDetails().size(), is(1));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 28 with QuestionGroupDetail

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

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

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

the class QuestionGroupInstanceDaoIntegrationTest method shouldPersistQuestionGroupInstance.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldPersistQuestionGroupInstance() throws SystemException {
    String title = "QG1" + currentTimeMillis();
    List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
    QuestionGroupInstance questionGroupInstance = getQuestionGroupInstance(1, questionGroup, 101, "Foo Bar1", "Foo Bar2");
    questionGroupInstanceDao.saveOrUpdateAll(asList(questionGroupInstance));
    QuestionGroupInstance groupInstance = questionGroupInstanceDao.getDetails(questionGroupInstance.getId());
    assertThat(groupInstance, is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().size(), is(2));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getSectionQuestion(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getSectionQuestion(), is(questionGroup.getSections().get(0).getQuestions().get(0)));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getResponse(), is("Foo Bar1"));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getSectionQuestion(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getSectionQuestion(), is(questionGroup.getSections().get(1).getQuestions().get(0)));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getResponse(), is("Foo Bar2"));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)74 Test (org.junit.Test)43 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)25 ArrayList (java.util.ArrayList)23 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)15 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)11 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)11 List (java.util.List)8 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)8 ValidationException (org.mifos.platform.validations.ValidationException)7 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)6 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)6 SystemException (org.mifos.framework.exceptions.SystemException)5 Arrays.asList (java.util.Arrays.asList)4 QuestionGroupReference (org.mifos.accounts.productdefinition.business.QuestionGroupReference)4 LoanProductBuilder (org.mifos.domain.builders.LoanProductBuilder)4 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 Transactional (org.springframework.transaction.annotation.Transactional)4 HashMap (java.util.HashMap)3