use of org.mifos.platform.questionnaire.domain.QuestionGroup in project head by mifos.
the class QuestionnaireMapperImpl method mapToQuestionGroup.
@Override
public QuestionGroup mapToQuestionGroup(QuestionGroupDto questionGroupDto) {
QuestionGroup questionGroup = new QuestionGroup();
questionGroup.setEditable(questionGroupDto.isEditable());
questionGroup.setDateOfCreation(getCurrentDateTime());
questionGroup.setPpi(questionGroupDto.isPpi());
questionGroup.setEventSources(mapEventSourceDtoToEntity(questionGroupDto.getEventSourceDtos()));
questionGroup.setTitle(questionGroupDto.getTitle());
questionGroup.setState(questionGroupDto.isActive() ? QuestionGroupState.ACTIVE : QuestionGroupState.INACTIVE);
questionGroup.setSections(mapToSectionsFromDtos(questionGroupDto.getSections()));
questionGroup.setActivityId(questionGroupDto.getActivityId());
return questionGroup;
}
use of org.mifos.platform.questionnaire.domain.QuestionGroup in project head by mifos.
the class QuestionnaireMapperTest method shouldMapToQuestionGroupInstanceDetails.
@Test
public void shouldMapToQuestionGroupInstanceDetails() {
QuestionGroupInstance questionGroupInstance1 = getQuestionGroupInstance("QG1", 2010, 7, 25);
QuestionGroupInstance questionGroupInstance2 = getQuestionGroupInstance("QG3", 2009, 2, 12);
QuestionGroup questionGroup = getQuestionGroup(1991, "QG5", getSectionWithOneMultiSelectQuestion(222, "Section3", "Question3", "Choice1", "Choice2", "Choice3", "Choice4"));
QuestionGroupInstance questionGroupInstance3 = getQuestionGroupInstanceWithSingleMultiSelectQuestion(101, 3, questionGroup, "Choice1", "Choice3", "Choice4");
List<QuestionGroupInstance> questionGroupInstances = asList(questionGroupInstance1, questionGroupInstance2, questionGroupInstance3);
List<QuestionGroupInstanceDetail> questionGroupInstanceDetails = questionnaireMapper.mapToQuestionGroupInstanceDetails(questionGroupInstances);
assertThat(questionGroupInstanceDetails, is(notNullValue()));
assertThat(questionGroupInstanceDetails.size(), is(3));
assertQuestionGroupInstanceDetail(questionGroupInstanceDetails.get(0), "QG1", 2010, 7, 25);
assertQuestionGroupInstanceDetail(questionGroupInstanceDetails.get(1), "QG3", 2009, 2, 12);
QuestionGroupInstanceDetail detail = questionGroupInstanceDetails.get(2);
assertThat(detail.getQuestionGroupTitle(), is("QG5"));
List<SelectionDetail> values = detail.getQuestionGroupDetail().getSectionDetail(0).getQuestionDetail(0).getSelections();
assertThat(values, is(notNullValue()));
assertThat(values.size(), is(3));
assertThat(values.get(0).getSelectedChoice(), is("Choice1"));
assertThat(values.get(1).getSelectedChoice(), is("Choice3"));
assertThat(values.get(2).getSelectedChoice(), is("Choice4"));
}
use of org.mifos.platform.questionnaire.domain.QuestionGroup in project head by mifos.
the class QuestionnaireMapperTest method shouldMapQuestionGroupDefinitionToExistingQuestionGroup.
@Test
public void shouldMapQuestionGroupDefinitionToExistingQuestionGroup() {
when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
when(questionDao.getDetails(12)).thenReturn(new QuestionEntity());
Section section = getSection("S1");
when(questionGroupDao.getDetails(123)).thenReturn(getQuestionGroup(123, "QG Title", section));
when(questionGroupDao.retrieveSectionByNameAndQuestionGroupId("S1", 123)).thenReturn(asList(section));
EventSourceDto eventSourceDto = getEventSource("Create", "Client");
List<SectionDetail> sectionDetails = asList(getSectionDefinition("S1", 12, TITLE), getSectionDefinition("S2", 0, TITLE));
QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(123, 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);
verify(questionGroupDao, times(1)).getDetails(123);
verify(questionGroupDao, times(1)).retrieveSectionByNameAndQuestionGroupId("S1", 123);
}
use of org.mifos.platform.questionnaire.domain.QuestionGroup in project head by mifos.
the class QuestionnaireMapperTest method getQuestionGroup.
private QuestionGroup getQuestionGroup(int id, String title, String event, String source, QuestionGroupState state, boolean editable, Section... sections) {
QuestionGroup questionGroup = new QuestionGroup();
questionGroup.setId(id);
questionGroup.setTitle(title);
questionGroup.setSections(asList(sections));
questionGroup.setState(state);
questionGroup.setEditable(editable);
questionGroup.setEventSources(getEventSources(event, source));
return questionGroup;
}
use of org.mifos.platform.questionnaire.domain.QuestionGroup in project head by mifos.
the class QuestionnaireMapperTest method shouldMapQuestionGroupToQuestionGroupDetail.
@Test
public void shouldMapQuestionGroupToQuestionGroupDetail() {
QuestionGroup questionGroup = getQuestionGroup("Create", "Client", "S1", "S2");
QuestionGroupDetail questionGroupDetail = questionnaireMapper.mapToQuestionGroupDetail(questionGroup);
assertThat(questionGroupDetail, is(notNullValue()));
assertThat(questionGroupDetail.getTitle(), is(TITLE));
assertThat(questionGroupDetail.isEditable(), is(true));
assertThat(questionGroupDetail.isActive(), is(true));
List<SectionDetail> sectionDetails = questionGroupDetail.getSectionDetails();
assertThat(sectionDetails, is(notNullValue()));
assertThat(questionGroupDetail.getSectionDetails().size(), is(2));
assertThat(questionGroupDetail.getSectionDetails().get(0).getName(), is("S1"));
assertThat(questionGroupDetail.getSectionDetails().get(1).getName(), is("S2"));
EventSourceDto eventSourceDto = questionGroupDetail.getEventSources().get(0);
assertThat(eventSourceDto, is(notNullValue()));
assertThat(eventSourceDto.getEvent(), is("Create"));
assertThat(eventSourceDto.getSource(), is("Client"));
}
Aggregations