use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto in project head by mifos.
the class QuestionGroupFormTest method shouldGetEventSourceId.
@Test
public void shouldGetEventSourceId() {
EventSourceDto eventSourceDto = new EventSourceDto("Create", "Client", "Create Client");
QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(123, "Title", Arrays.asList(eventSourceDto), new ArrayList<SectionDetail>(), false);
QuestionGroupForm questionGroupForm = new QuestionGroupForm(questionGroupDetail);
assertThat(questionGroupForm.getEventSourceIds().get(0), is("Create.Client"));
}
use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto 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.dtos.EventSourceDto in project head by mifos.
the class QuestionnaireMapperTest method shouldMapToEventSources.
@Test
public void shouldMapToEventSources() {
List<EventSourceEntity> events = getEventSourceEntities("Create", "Client", "Create Client");
List<EventSourceDto> eventSourceDtos = questionnaireMapper.mapToEventSources(events);
assertThat(eventSourceDtos, is(notNullValue()));
assertThat(eventSourceDtos, new EventSourcesMatcher(asList(getEventSource("Create", "Client", "Create Client"))));
}
use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto 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.service.dtos.EventSourceDto 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