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");
}
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));
}
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);
}
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()));
}
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"));
}
Aggregations