use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto 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.dtos.EventSourceDto in project head by mifos.
the class QuestionnaireServiceTest method shouldGetQuestionGroupInstancesIncludingUnansweredQuestionGroups.
@Test
public void shouldGetQuestionGroupInstancesIncludingUnansweredQuestionGroups() {
List<Section> sections = new ArrayList<Section>();
List<QuestionGroup> questionGroups = asList(getQuestionGroup(4041, "QG1", sections), getQuestionGroup(4042, "QG2", sections), getQuestionGroup(4043, "QG3", sections), getQuestionGroup(4044, "QG4", sections));
List<QuestionGroupInstance> questionGroupInstances = asList(getQuestionGroupInstance(3031, 2010, 7, 26, questionGroups.get(0)), getQuestionGroupInstance(3032, 2010, 7, 26, questionGroups.get(1)), getQuestionGroupInstance(3033, 2010, 7, 26, questionGroups.get(2)), getQuestionGroupInstance(3034, 2010, 7, 25, questionGroups.get(0)), getQuestionGroupInstance(3035, 2010, 7, 25, questionGroups.get(1)), getQuestionGroupInstance(3036, 2010, 7, 24, questionGroups.get(1)), getQuestionGroupInstance(3037, 2010, 7, 24, questionGroups.get(2)));
when(questionGroupDao.retrieveQuestionGroupsByEventSource("View", "Client")).thenReturn(questionGroups);
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, true, false);
assertThat(instances, is(notNullValue()));
assertThat(instances.size(), is(8));
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 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.dtos.EventSourceDto in project head by mifos.
the class QuestionnaireValidatorIntegrationTest method shouldCheckForInValidEventSource.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldCheckForInValidEventSource() {
EventSourceDto eventSourceDto = new EventSourceDto("Disburse", "Client", "Disburse Client");
try {
questionnaireValidator.validateForEventSource(eventSourceDto);
fail("Should have raised a validation error for invalid event");
} catch (SystemException e) {
assertThat(e.getKey(), is(QuestionnaireConstants.INVALID_EVENT_SOURCE));
}
}
use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto in project head by mifos.
the class QuestionnaireValidatorIntegrationTest method shouldCheckForValidEventSource.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldCheckForValidEventSource() {
EventSourceDto eventSourceDto = new EventSourceDto("Create", "Client", "Create Client");
try {
questionnaireValidator.validateForEventSource(eventSourceDto);
eventSourceDto = new EventSourceDto("View", "Client", "View Client");
questionnaireValidator.validateForEventSource(eventSourceDto);
eventSourceDto = new EventSourceDto("Create", "Loan", "Create Loan");
questionnaireValidator.validateForEventSource(eventSourceDto);
} catch (SystemException e) {
fail("Should not have raised a validation error for this event");
}
}
Aggregations