use of org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail in project head by mifos.
the class QuestionnaireServiceTest method shouldGetQuestionGroupInstances.
@Test
public void shouldGetQuestionGroupInstances() {
List<Section> sections = new ArrayList<Section>();
List<QuestionGroupInstance> questionGroupInstances = asList(getQuestionGroupInstance(3031, 2010, 7, 26, getQuestionGroup(4041, "QG1", sections)), getQuestionGroupInstance(3032, 2010, 7, 26, getQuestionGroup(4042, "QG2", sections)), getQuestionGroupInstance(3033, 2010, 7, 26, getQuestionGroup(4043, "QG3", sections)), getQuestionGroupInstance(3034, 2010, 7, 25, getQuestionGroup(4041, "QG1", sections)), getQuestionGroupInstance(3035, 2010, 7, 25, getQuestionGroup(4042, "QG2", sections)), getQuestionGroupInstance(3036, 2010, 7, 24, getQuestionGroup(4042, "QG2", sections)), getQuestionGroupInstance(3037, 2010, 7, 24, getQuestionGroup(4043, "QG3", sections)));
when(questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, 202)).thenReturn(questionGroupInstances);
when(eventSourceDao.retrieveByEventAndSource("View", "Client")).thenReturn(asList(getEventSourceEntity(202)));
EventSourceDto eventSourceDto = new EventSourceDto("View", "Client", "View.Client");
List<QuestionGroupInstanceDetail> instances = questionnaireService.getQuestionGroupInstances(101, eventSourceDto, false, false);
assertThat(instances, is(notNullValue()));
assertThat(instances.size(), is(7));
assertQuestionGroupInstanceDetail(instances.get(0), "QG1", 2010, 7, 26, questionGroupInstances.get(0).getId());
assertQuestionGroupInstanceDetail(instances.get(1), "QG2", 2010, 7, 26, questionGroupInstances.get(1).getId());
assertQuestionGroupInstanceDetail(instances.get(2), "QG3", 2010, 7, 26, questionGroupInstances.get(2).getId());
assertQuestionGroupInstanceDetail(instances.get(3), "QG1", 2010, 7, 25, questionGroupInstances.get(3).getId());
assertQuestionGroupInstanceDetail(instances.get(4), "QG2", 2010, 7, 25, questionGroupInstances.get(4).getId());
assertQuestionGroupInstanceDetail(instances.get(5), "QG2", 2010, 7, 24, questionGroupInstances.get(5).getId());
assertQuestionGroupInstanceDetail(instances.get(6), "QG3", 2010, 7, 24, questionGroupInstances.get(6).getId());
verify(questionGroupInstanceDao, times(1)).retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, 202);
verify(questionnaireValidator, times(1)).validateForEventSource(eventSourceDto);
verify(eventSourceDao, times(1)).retrieveByEventAndSource("View", "Client");
}
use of org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail 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.service.QuestionGroupInstanceDetail in project head by mifos.
the class QuestionnaireMapperTest method shouldMapToEmptyQuestionGroupInstanceDetail.
@Test
public void shouldMapToEmptyQuestionGroupInstanceDetail() {
QuestionGroupInstanceDetail detail = questionnaireMapper.mapToEmptyQuestionGroupInstanceDetail(getQuestionGroup(1991, "QG1", getSection("Section1")));
assertThat(detail, is(notNullValue()));
assertThat(detail.getQuestionGroupDetail().getId(), is(1991));
assertThat(detail.getQuestionGroupTitle(), is("QG1"));
assertThat(detail.getId(), is(0));
}
use of org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail in project head by mifos.
the class QuestionnaireServiceTest method shouldGetLatestQuestionGroupInstances.
@Test
public void shouldGetLatestQuestionGroupInstances() {
List<Section> sections = new ArrayList<Section>();
List<QuestionGroupInstance> questionGroupInstances = asList(getQuestionGroupInstance(3033, 2010, 7, 26, getQuestionGroup(4043, "QG2", sections)), getQuestionGroupInstance(3034, 2010, 7, 25, getQuestionGroup(4041, "QG1", sections)), getQuestionGroupInstance(3037, 2010, 7, 24, getQuestionGroup(4043, "QG3", sections)));
when(questionGroupInstanceDao.retrieveLatestQuestionGroupInstancesByEntityIdAndEventSourceId(101, 202)).thenReturn(questionGroupInstances);
when(eventSourceDao.retrieveByEventAndSource("View", "Client")).thenReturn(asList(getEventSourceEntity(202)));
EventSourceDto eventSourceDto = new EventSourceDto("View", "Client", "View.Client");
List<QuestionGroupInstanceDetail> instances = questionnaireService.getQuestionGroupInstances(101, eventSourceDto, false, true);
assertThat(instances, is(notNullValue()));
assertThat(instances.size(), is(3));
assertQuestionGroupInstanceDetail(instances.get(0), "QG2", 2010, 7, 26, questionGroupInstances.get(0).getId());
assertQuestionGroupInstanceDetail(instances.get(1), "QG1", 2010, 7, 25, questionGroupInstances.get(1).getId());
assertQuestionGroupInstanceDetail(instances.get(2), "QG3", 2010, 7, 24, questionGroupInstances.get(2).getId());
verify(questionGroupInstanceDao, times(1)).retrieveLatestQuestionGroupInstancesByEntityIdAndEventSourceId(101, 202);
verify(questionnaireValidator, times(1)).validateForEventSource(eventSourceDto);
verify(eventSourceDao, times(1)).retrieveByEventAndSource("View", "Client");
}
use of org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail in project head by mifos.
the class QuestionnaireServiceTest method shouldGetQuestionGroupInstance.
@Test
public void shouldGetQuestionGroupInstance() {
QuestionGroupInstance questionGroupInstance = getQuestionGroupInstance(12, 1, getQuestionGroup(54, "QG1", asList(getSectionWithQuestions(89, "Sec1", "Ques1"))), "Hello");
when(questionGroupInstanceDao.getDetails(1212)).thenReturn(questionGroupInstance);
QuestionGroupInstanceDetail questionGroupInstanceDetail = questionnaireService.getQuestionGroupInstance(1212);
assertThat(questionGroupInstanceDetail, is(notNullValue()));
assertThat(questionGroupInstanceDetail.getQuestionGroupTitle(), is("QG1"));
verify(questionGroupInstanceDao, times(1)).getDetails(1212);
}
Aggregations