Search in sources :

Example 6 with EventSourceEntity

use of org.mifos.platform.questionnaire.domain.EventSourceEntity in project head by mifos.

the class QuestionnaireMapperTest method getEventSources.

private HashSet<EventSourceEntity> getEventSources(String event, String source) {
    EventSourceEntity eventSourceEntity = new EventSourceEntity();
    EventEntity eventEntity = new EventEntity();
    eventEntity.setName(event);
    eventSourceEntity.setEvent(eventEntity);
    EntityMaster entityMaster = new EntityMaster();
    entityMaster.setEntityType(source);
    eventSourceEntity.setSource(entityMaster);
    HashSet<EventSourceEntity> eventSources = new HashSet<EventSourceEntity>();
    eventSources.add(eventSourceEntity);
    return eventSources;
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) EventEntity(org.mifos.platform.questionnaire.domain.EventEntity) EntityMaster(org.mifos.framework.business.EntityMaster) HashSet(java.util.HashSet)

Example 7 with EventSourceEntity

use of org.mifos.platform.questionnaire.domain.EventSourceEntity in project head by mifos.

the class QuestionnaireMapperTest method assertQuestionGroupEntity.

private void assertQuestionGroupEntity(QuestionGroup questionGroup) {
    assertThat(questionGroup, is(notNullValue()));
    assertThat(questionGroup.getTitle(), is("QG1"));
    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().getQuestionText(), is("Ques1"));
    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().getQuestionText(), is("Ques2"));
    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("Ch1"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceOrder(), is(1));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceText(), is("Ch2"));
    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 8 with EventSourceEntity

use of org.mifos.platform.questionnaire.domain.EventSourceEntity in project head by mifos.

the class QuestionnaireMapperTest method getEventSourceEntities.

private List<EventSourceEntity> getEventSourceEntities(String event, String source, String description) {
    List<EventSourceEntity> events = new ArrayList<EventSourceEntity>();
    EventSourceEntity eventSourceEntity = new EventSourceEntity();
    eventSourceEntity.setDescription(description);
    EventEntity eventEntity = new EventEntity();
    eventEntity.setName(event);
    eventSourceEntity.setEvent(eventEntity);
    EntityMaster entityMaster = new EntityMaster();
    entityMaster.setEntityType(source);
    eventSourceEntity.setSource(entityMaster);
    events.add(eventSourceEntity);
    return events;
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) ArrayList(java.util.ArrayList) EventEntity(org.mifos.platform.questionnaire.domain.EventEntity) EntityMaster(org.mifos.framework.business.EntityMaster)

Example 9 with EventSourceEntity

use of org.mifos.platform.questionnaire.domain.EventSourceEntity in project head by mifos.

the class QuestionnaireMapperTest method getEventSourceEntity.

private EventSourceEntity getEventSourceEntity(String event, String source) {
    EventSourceEntity eventSource = new EventSourceEntity();
    EventEntity eventEntity = new EventEntity();
    eventEntity.setName(event);
    eventSource.setEvent(eventEntity);
    EntityMaster entityMaster = new EntityMaster();
    entityMaster.setEntityType(source);
    eventSource.setSource(entityMaster);
    return eventSource;
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) EventEntity(org.mifos.platform.questionnaire.domain.EventEntity) EntityMaster(org.mifos.framework.business.EntityMaster)

Example 10 with EventSourceEntity

use of org.mifos.platform.questionnaire.domain.EventSourceEntity in project head by mifos.

the class QuestionnaireMapperTest method shouldMapQuestionGroupToExistingQuestionGroupWhileAddingQuestionToOldSection.

@Test
public void shouldMapQuestionGroupToExistingQuestionGroupWhileAddingQuestionToOldSection() {
    Integer questionGroupId = 123;
    EventSourceDto eventSourceDto = getEventSource("Create", "Client");
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setName("Misc");
    SectionQuestionDetail sectionQuestionDetail1 = getSectionQuestionDetail(111, 999, "Ques1");
    SectionQuestionDetail sectionQuestionDetail2 = getSectionQuestionDetail(0, 0, "Ques2");
    sectionDetail.setQuestionDetails(asList(sectionQuestionDetail1, sectionQuestionDetail2));
    List<SectionDetail> sectionDetails = asList(sectionDetail);
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(questionGroupId, TITLE, Arrays.asList(eventSourceDto), sectionDetails, true, true);
    SectionQuestion sectionQuestion = getSectionQuestion(getQuestionEntity(999, "Ques1"), 333);
    Section section = getSection(sectionQuestion, 222, "Misc");
    when(questionGroupDao.retrieveSectionByNameAndQuestionGroupId("Misc", 123)).thenReturn(asList(section));
    when(questionGroupDao.getDetails(questionGroupId)).thenReturn(getQuestionGroup(questionGroupId, "QG Title", section));
    when(sectionQuestionDao.retrieveFromQuestionIdSectionId(222, 999)).thenReturn(asList(sectionQuestion));
    when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
    QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(questionGroupDetail);
    assertQuestionGroupForExistingQuestion(questionGroup, QuestionGroupState.ACTIVE);
    verify(questionGroupDao).retrieveSectionByNameAndQuestionGroupId("Misc", 123);
    verify(questionGroupDao).getDetails(questionGroupId);
    verify(sectionQuestionDao).retrieveFromQuestionIdSectionId(222, 999);
    verify(eventSourceDao).retrieveByEventAndSource(anyString(), anyString());
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) 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