Search in sources :

Example 1 with EventSourceEntity

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));
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 2 with EventSourceEntity

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));
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) Section(org.mifos.platform.questionnaire.domain.Section)

Example 3 with EventSourceEntity

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);
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 4 with EventSourceEntity

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"))));
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) EventSourcesMatcher(org.mifos.platform.questionnaire.matchers.EventSourcesMatcher) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 5 with EventSourceEntity

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);
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Section(org.mifos.platform.questionnaire.domain.Section) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Aggregations

EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)11 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)5 Test (org.junit.Test)4 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)4 Section (org.mifos.platform.questionnaire.domain.Section)4 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)4 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)4 EntityMaster (org.mifos.framework.business.EntityMaster)3 EventEntity (org.mifos.platform.questionnaire.domain.EventEntity)3 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EventSourcesMatcher (org.mifos.platform.questionnaire.matchers.EventSourcesMatcher)1 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)1