Search in sources :

Example 11 with QuestionGroupResponse

use of org.mifos.platform.questionnaire.domain.QuestionGroupResponse 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)

Example 12 with QuestionGroupResponse

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

the class QuestionnaireServiceIntegrationTest method shouldSaveQuestionGroupInstance.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldSaveQuestionGroupInstance() {
    String title = "QG1" + currentTimeMillis();
    QuestionGroupDetail qgDetail = defineQuestionGroup(title, "Create", "Client", asList(getSection("S1")), true);
    Integer sectionQuestionId = qgDetail.getSectionDetail(0).getQuestionDetail(0).getId();
    QuestionGroupInstanceDto qgInstanceDto = getQuestionGroupInstanceDto("1234", 121, 567, qgDetail.getId(), sectionQuestionId);
    Integer qgInstanceId = questionnaireService.saveQuestionGroupInstance(qgInstanceDto);
    assertThat(qgInstanceId, is(notNullValue()));
    QuestionGroupInstance instance = questionGroupInstanceDao.getDetails(qgInstanceId);
    assertThat(instance, is(notNullValue()));
    assertThat(instance.getCreatorId(), is(121));
    assertThat(instance.getEntityId(), is(567));
    List<QuestionGroupResponse> questionGroupResponses = instance.getQuestionGroupResponses();
    assertThat(questionGroupResponses, is(notNullValue()));
    assertThat(questionGroupResponses.size(), is(1));
    assertThat(questionGroupResponses.get(0).getResponse(), is("1234"));
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) QuestionGroupInstanceDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with QuestionGroupResponse

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

the class QuestionnaireServiceIntegrationTest method shouldSaveResponse.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldSaveResponse() throws SystemException {
    String title = "QG1" + currentTimeMillis();
    List<SectionDetail> details = asList(getSection("S1"), getSectionWithSmartSelectQuestion("S2"));
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, true);
    questionGroupDetail.getSectionDetail(0).getQuestionDetail(0).setValue("1");
    SelectionDetail selectionDetail1 = getSelectionDetail("Ch1", "Tag2");
    SelectionDetail selectionDetail2 = getSelectionDetail("Ch3", "Tag1");
    questionGroupDetail.getSectionDetail(1).getQuestionDetail(0).setSelections(asList(selectionDetail1, selectionDetail2));
    questionnaireService.saveResponses(new QuestionGroupDetails(1, 1, 1, asList(questionGroupDetail)));
    List<QuestionGroupInstance> instances = questionGroupInstanceDao.getDetailsAll();
    assertThat(instances.size(), is(1));
    QuestionGroupInstance instance = getMatchingQuestionGroupInstance(questionGroupDetail.getId(), 1, instances, 0);
    assertThat(instance, is(notNullValue()));
    List<QuestionGroupResponse> groupResponses = instance.getQuestionGroupResponses();
    assertThat(groupResponses.size(), is(3));
    Assert.assertEquals(groupResponses.get(0).getResponse(), "1");
    Assert.assertEquals(groupResponses.get(1).getResponse(), "Ch1");
    Assert.assertEquals(groupResponses.get(1).getTag(), "Tag2");
    Assert.assertEquals(groupResponses.get(2).getResponse(), "Ch3");
    Assert.assertEquals(groupResponses.get(2).getTag(), "Tag1");
    questionGroupDetail.getSectionDetail(0).getQuestionDetail(0).setValue("3");
    questionnaireService.saveResponses(new QuestionGroupDetails(1, 1, 1, asList(questionGroupDetail)));
    instances = questionGroupInstanceDao.getDetailsAll();
    assertThat(instances.size(), is(2));
    instance = getMatchingQuestionGroupInstance(questionGroupDetail.getId(), 1, instances, 1);
    assertThat(instance, is(notNullValue()));
    groupResponses = instance.getQuestionGroupResponses();
    Assert.assertEquals(groupResponses.get(0).getResponse(), "3");
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)13 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)7 Test (org.junit.Test)5 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 ArrayList (java.util.ArrayList)3 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)3 Transactional (org.springframework.transaction.annotation.Transactional)3 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)2 QuestionGroupInstanceDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto)2 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)1 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)1 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)1 SelectionDetail (org.mifos.platform.questionnaire.service.SelectionDetail)1 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)1 Matchers.anyString (org.mockito.Matchers.anyString)1