use of org.mifos.platform.questionnaire.domain.EventSourceEntity in project head by mifos.
the class QuestionnaireMapperIntegrationTest method testMapEventSource.
private void testMapEventSource(String event, String source, String description) {
EventSourceDto eventSourceDto = new EventSourceDto(event, source, description);
List<SectionDetail> sectionDetails = getSectionDefinitions();
QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(new QuestionGroupDetail(0, "Title", Arrays.asList(eventSourceDto), sectionDetails, false));
Set<EventSourceEntity> eventSources = questionGroup.getEventSources();
assertThat(eventSources, is(not(nullValue())));
assertThat(eventSources.size(), is(1));
EventSourceEntity eventSourceEntity = eventSources.toArray(new EventSourceEntity[eventSources.size()])[0];
assertThat(eventSourceEntity.getEvent().getName(), is(event));
assertThat(eventSourceEntity.getSource().getEntityType(), is(source));
assertThat(eventSourceEntity.getDescription(), is(description));
assertThat(eventSourceEntity.getEvent().getName(), is(event));
assertThat(eventSourceEntity.getSource().getEntityType(), is(source));
assertThat(eventSourceEntity.getDescription(), is(description));
}
use of org.mifos.platform.questionnaire.domain.EventSourceEntity in project head by mifos.
the class QuestionnaireServiceIntegrationTest method assertQuestionGroup.
private void assertQuestionGroup(QuestionGroup questionGroup, String questionGroupTitle, String firstQuestionTitle, String secondQuestionTitle) {
assertThat(questionGroup, is(notNullValue()));
assertThat(questionGroup.getTitle(), is(questionGroupTitle));
Set<EventSourceEntity> eventSources = questionGroup.getEventSources();
assertThat(eventSources, is(notNullValue()));
assertThat(eventSources.size(), is(1));
EventSourceEntity eventSourceEntity = eventSources.toArray(new EventSourceEntity[eventSources.size()])[0];
assertThat(eventSourceEntity.getEvent().getName(), is("Create"));
assertThat(eventSourceEntity.getSource().getEntityType(), is("Client"));
assertThat(questionGroup.getState(), is(QuestionGroupState.ACTIVE));
List<Section> sections = questionGroup.getSections();
assertThat(sections, is(notNullValue()));
assertThat(sections.size(), is(1));
Section section = sections.get(0);
assertThat(section.getName(), is("Sec1"));
List<SectionQuestion> questions = section.getQuestions();
assertThat(questions, is(notNullValue()));
assertThat(questions.size(), is(2));
SectionQuestion sectionQuestion1 = questions.get(0);
assertThat(sectionQuestion1.getSequenceNumber(), is(1));
assertThat(sectionQuestion1.getSection(), is(notNullValue()));
assertThat(sectionQuestion1.getSection().getName(), is("Sec1"));
assertThat(sectionQuestion1.getSection().getSequenceNumber(), is(1));
assertThat(sectionQuestion1.getQuestion(), is(notNullValue()));
assertThat(sectionQuestion1.getQuestion().getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
assertThat(sectionQuestion1.getQuestion().getQuestionText(), is(firstQuestionTitle));
assertThat(sectionQuestion1.getQuestion().getAnswerTypeAsEnum(), is(AnswerType.FREETEXT));
SectionQuestion sectionQuestion2 = questions.get(1);
assertThat(sectionQuestion2.getSequenceNumber(), is(2));
assertThat(sectionQuestion2.getSection(), is(notNullValue()));
assertThat(sectionQuestion2.getSection().getName(), is("Sec1"));
assertThat(sectionQuestion2.getSection().getSequenceNumber(), is(1));
assertThat(sectionQuestion2.getQuestion(), is(notNullValue()));
assertThat(sectionQuestion2.getQuestion().getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
assertThat(sectionQuestion2.getQuestion().getQuestionText(), is(secondQuestionTitle));
assertThat(sectionQuestion2.getQuestion().getAnswerTypeAsEnum(), is(AnswerType.SINGLESELECT));
assertThat(sectionQuestion2.getQuestion().getChoices(), is(notNullValue()));
assertThat(sectionQuestion2.getQuestion().getChoices().size(), is(3));
assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceText(), is("Ch2"));
assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceOrder(), is(1));
assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceText(), is("Ch1"));
assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceOrder(), is(2));
assertThat(sectionQuestion2.getQuestion().getChoices().get(2).getChoiceText(), is("Ch3"));
assertThat(sectionQuestion2.getQuestion().getChoices().get(2).getChoiceOrder(), is(3));
}
use of org.mifos.platform.questionnaire.domain.EventSourceEntity 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.domain.EventSourceEntity 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.domain.EventSourceEntity 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);
}
Aggregations