Search in sources :

Example 26 with EventSourceDto

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");
}
Also used : ArrayList(java.util.ArrayList) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) Test(org.junit.Test)

Example 27 with EventSourceDto

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"))));
}
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 28 with EventSourceDto

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);
}
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)

Example 29 with EventSourceDto

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"));
}
Also used : 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) Test(org.junit.Test)

Example 30 with EventSourceDto

use of org.mifos.platform.questionnaire.service.dtos.EventSourceDto in project head by mifos.

the class QuestionnaireMapperTest method shouldMapToQuestionGroupInstances.

@Test
public void shouldMapToQuestionGroupInstances() {
    QuestionGroup questionGroup1 = new QuestionGroup();
    questionGroup1.setId(10);
    when(questionGroupDao.getDetails(10)).thenReturn(questionGroup1);
    QuestionGroup questionGroup2 = new QuestionGroup();
    questionGroup2.setId(11);
    when(questionGroupDao.getDetails(11)).thenReturn(questionGroup2);
    SectionQuestion sectionQuestion1 = new SectionQuestion();
    sectionQuestion1.setId(14);
    when(sectionQuestionDao.getDetails(14)).thenReturn(sectionQuestion1);
    SectionQuestion sectionQuestion2 = new SectionQuestion();
    sectionQuestion2.setId(15);
    when(sectionQuestionDao.getDetails(15)).thenReturn(sectionQuestion2);
    QuestionGroupInstance questionGroupInstance = new QuestionGroupInstance();
    questionGroupInstance.setVersionNum(3);
    when(questionGroupInstanceDao.retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(201, 10)).thenReturn(asList(questionGroupInstance));
    when(questionGroupInstanceDao.retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(201, 11)).thenReturn(asList(questionGroupInstance));
    List<QuestionDetail> questionDetails1 = asList(new QuestionDetail(12, "Question 1", QuestionType.FREETEXT, true, true));
    List<SectionDetail> sectionDetails1 = asList(getSectionDetailWithQuestions(14, "Sec1", questionDetails1, "value", null));
    QuestionGroupDetail questionGroupDetail1 = new QuestionGroupDetail(10, "QG1", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails1, true);
    List<QuestionDetail> questionDetails2 = asList(new QuestionDetail(13, "Question 2", QuestionType.DATE, true, true));
    List<SectionDetail> sectionDetails2 = asList(getSectionDetailWithQuestions(15, "Sec2", questionDetails2, null, null));
    QuestionGroupDetail questionGroupDetail2 = new QuestionGroupDetail(11, "QG2", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails2, true);
    QuestionDetail questionDetail1 = new QuestionDetail(13, "Question 3", QuestionType.MULTI_SELECT, true, true);
    questionDetail1.setAnswerChoices(asList(getChoiceDto("a1"), getChoiceDto("a2"), getChoiceDto("a3")));
    List<QuestionDetail> questionDetails3 = asList(questionDetail1);
    List<SectionDetail> sectionDetails3 = asList(getSectionDetailWithQuestions(15, "Sec2", questionDetails3, null, asList("a2", "a3")));
    QuestionGroupDetail questionGroupDetail3 = new QuestionGroupDetail(11, "QG2", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails3, true);
    QuestionDetail questionDetail2 = new QuestionDetail(13, "Question 4", QuestionType.SMART_SELECT, true, true);
    questionDetail2.setAnswerChoices(asList(getChoiceDto("a1", "Tag1", "Tag2"), getChoiceDto("a2", "Tag11", "Tag22"), getChoiceDto("a3", "Tag111", "Tag222")));
    questionDetails3 = asList(questionDetail2);
    sectionDetails3 = asList(getSectionDetailWithQuestions(15, "Sec2", questionDetails3, asList(getSelectionDetail("a1", "Tag2"), getSelectionDetail("a3", "Tag111"))));
    QuestionGroupDetail questionGroupDetail4 = new QuestionGroupDetail(11, "QG2", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails3, true);
    List<QuestionGroupInstance> questionGroupInstances = questionnaireMapper.mapToQuestionGroupInstances(new QuestionGroupDetails(101, 201, 1, asList(questionGroupDetail1, questionGroupDetail2, questionGroupDetail3, questionGroupDetail4)));
    assertThat(questionGroupInstances, is(notNullValue()));
    assertThat(questionGroupInstances.size(), is(4));
    QuestionGroupInstance questionGroupInstance1 = questionGroupInstances.get(0);
    assertThat(questionGroupInstance1.getQuestionGroup().getId(), is(10));
    assertThat(questionGroupInstance1.getCompletedStatus(), is(1));
    assertThat(questionGroupInstance1.getCreatorId(), is(101));
    assertThat(questionGroupInstance1.getDateConducted(), is(notNullValue()));
    assertThat(questionGroupInstance1.getEntityId(), is(201));
    assertThat(questionGroupInstance1.getVersionNum(), is(4));
    List<QuestionGroupResponse> questionGroupResponses1 = questionGroupInstance1.getQuestionGroupResponses();
    assertThat(questionGroupResponses1, is(notNullValue()));
    assertThat(questionGroupResponses1.size(), is(1));
    QuestionGroupResponse questionGroupResponse = questionGroupResponses1.get(0);
    assertThat(questionGroupResponse.getResponse(), is("value"));
    assertThat(questionGroupResponse.getSectionQuestion().getId(), is(14));
    QuestionGroupInstance questionGroupInstance2 = questionGroupInstances.get(1);
    assertThat(questionGroupInstance2.getQuestionGroup().getId(), is(11));
    assertThat(questionGroupInstance2.getCompletedStatus(), is(1));
    assertThat(questionGroupInstance2.getCreatorId(), is(101));
    assertThat(questionGroupInstance2.getDateConducted(), is(notNullValue()));
    assertThat(questionGroupInstance2.getEntityId(), is(201));
    assertThat(questionGroupInstance2.getVersionNum(), is(4));
    List<QuestionGroupResponse> questionGroupResponses2 = questionGroupInstance2.getQuestionGroupResponses();
    assertThat(questionGroupResponses2, is(notNullValue()));
    assertThat(questionGroupResponses2.size(), is(0));
    QuestionGroupInstance questionGroupInstance3 = questionGroupInstances.get(2);
    assertThat(questionGroupInstance3.getQuestionGroup().getId(), is(11));
    assertThat(questionGroupInstance3.getCompletedStatus(), is(1));
    assertThat(questionGroupInstance3.getCreatorId(), is(101));
    assertThat(questionGroupInstance3.getDateConducted(), is(notNullValue()));
    assertThat(questionGroupInstance3.getEntityId(), is(201));
    assertThat(questionGroupInstance3.getVersionNum(), is(4));
    List<QuestionGroupResponse> questionGroupResponses3 = questionGroupInstance3.getQuestionGroupResponses();
    assertThat(questionGroupInstance3, is(notNullValue()));
    assertThat(questionGroupResponses3.size(), is(2));
    assertThat(questionGroupResponses3.get(0).getResponse(), is("a2"));
    assertThat(questionGroupResponses3.get(1).getResponse(), is("a3"));
    QuestionGroupInstance questionGroupInstance4 = questionGroupInstances.get(3);
    List<QuestionGroupResponse> questionGroupResponses4 = questionGroupInstance4.getQuestionGroupResponses();
    assertThat(questionGroupInstance4, is(notNullValue()));
    assertThat(questionGroupResponses4.size(), is(2));
    assertThat(questionGroupResponses4.get(0).getResponse(), is("a1"));
    assertThat(questionGroupResponses4.get(0).getTag(), is("Tag2"));
    assertThat(questionGroupResponses4.get(1).getResponse(), is("a3"));
    assertThat(questionGroupResponses4.get(1).getTag(), is("Tag111"));
    verify(questionGroupInstanceDao, times(1)).retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(201, 10);
    verify(questionGroupInstanceDao, times(3)).retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(201, 11);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroupDetails(org.mifos.platform.questionnaire.service.QuestionGroupDetails) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) Test(org.junit.Test)

Aggregations

EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)39 Test (org.junit.Test)28 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)15 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)12 ArrayList (java.util.ArrayList)10 Transactional (org.springframework.transaction.annotation.Transactional)7 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)6 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)5 SystemException (org.mifos.framework.exceptions.SystemException)4 EventSourcesMatcher (org.mifos.platform.questionnaire.matchers.EventSourcesMatcher)3 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)3 QuestionGroupInstanceDetail (org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail)3 ValidationException (org.mifos.platform.validations.ValidationException)3 LinkedHashMap (java.util.LinkedHashMap)2 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)2 Section (org.mifos.platform.questionnaire.domain.Section)2 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)2 MandatoryAnswerNotFoundException (org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException)2 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)2