Search in sources :

Example 6 with QuestionGroup

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

the class QuestionnaireMapperTest method getQuestionGroup.

private QuestionGroup getQuestionGroup(int id, String title, Section... sections) {
    QuestionGroup questionGroup = new QuestionGroup();
    questionGroup.setId(id);
    questionGroup.setTitle(title);
    questionGroup.setSections(asList(sections));
    return questionGroup;
}
Also used : QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup)

Example 7 with QuestionGroup

use of org.mifos.platform.questionnaire.domain.QuestionGroup 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 8 with QuestionGroup

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

the class QuestionGroupInstanceDaoIntegrationTest method shouldGetAllLatestQuestionGroupInstancesByEntityAndEventSourceId.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldGetAllLatestQuestionGroupInstancesByEntityAndEventSourceId() {
    List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
    QuestionGroup questionGroup1 = questionGroupDao.getDetails(defineQuestionGroup("QG2" + currentTimeMillis(), "View", "Client", details, false).getId());
    QuestionGroup questionGroup2 = questionGroupDao.getDetails(defineQuestionGroup("QG1" + currentTimeMillis(), "View", "Client", details, false).getId());
    QuestionGroup questionGroup3 = questionGroupDao.getDetails(defineQuestionGroup("QG3" + currentTimeMillis(), "View", "Client", details, false).getId());
    List<QuestionGroupInstance> questionGroupInstances = asList(getQuestionGroupInstance(2010, 7, 24, questionGroup1, 101, 1), getQuestionGroupInstance(2010, 7, 25, questionGroup1, 101, 2), getQuestionGroupInstance(2010, 7, 24, questionGroup2, 101, 1), getQuestionGroupInstance(2010, 7, 25, questionGroup2, 101, 2), getQuestionGroupInstance(2010, 7, 26, questionGroup2, 101, 3), getQuestionGroupInstance(2010, 7, 24, questionGroup3, 101, 1), getQuestionGroupInstance(2010, 7, 26, questionGroup3, 101, 2));
    questionGroupInstanceDao.saveOrUpdateAll(questionGroupInstances);
    int eventSourceId = eventSourceDao.retrieveByEventAndSource("View", "Client").get(0).getId();
    //  questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId)
    //  is a hack to flush the entities as method under test is in SQL and not HQL
    questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId);
    List<QuestionGroupInstance> list = questionGroupInstanceDao.retrieveLatestQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId);
    assertThat(list, is(notNullValue()));
    assertThat(list.size(), is(3));
    assertThat((list.get(0)).getId(), is(questionGroupInstances.get(4).getId()));
    assertThat((list.get(1)).getId(), is(questionGroupInstances.get(6).getId()));
    assertThat((list.get(2)).getId(), is(questionGroupInstances.get(1).getId()));
}
Also used : QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with QuestionGroup

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

the class QuestionGroupInstanceDaoIntegrationTest method shouldPersistQuestionGroupInstance.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldPersistQuestionGroupInstance() throws SystemException {
    String title = "QG1" + currentTimeMillis();
    List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
    QuestionGroupInstance questionGroupInstance = getQuestionGroupInstance(1, questionGroup, 101, "Foo Bar1", "Foo Bar2");
    questionGroupInstanceDao.saveOrUpdateAll(asList(questionGroupInstance));
    QuestionGroupInstance groupInstance = questionGroupInstanceDao.getDetails(questionGroupInstance.getId());
    assertThat(groupInstance, is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().size(), is(2));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getSectionQuestion(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getSectionQuestion(), is(questionGroup.getSections().get(0).getQuestions().get(0)));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getResponse(), is("Foo Bar1"));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getSectionQuestion(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getSectionQuestion(), is(questionGroup.getSections().get(1).getQuestions().get(0)));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getResponse(), is("Foo Bar2"));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with QuestionGroup

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

the class QuestionGroupInstanceDaoIntegrationTest method shouldGetLatestQuestionGroupInstancesBasedOnQuestionGroupAndEntity.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldGetLatestQuestionGroupInstancesBasedOnQuestionGroupAndEntity() {
    String title = "QG1" + currentTimeMillis();
    List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
    QuestionGroupInstance instance1 = getQuestionGroupInstance(1, questionGroup, 101, "Foo Bar1", "Foo Bar2");
    QuestionGroupInstance instance2 = getQuestionGroupInstance(2, questionGroup, 101, "Hello World1", "Hello World2");
    questionGroupInstanceDao.saveOrUpdateAll(asList(instance1, instance2));
    List<QuestionGroupInstance> instances = questionGroupInstanceDao.retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(101, questionGroupDetail.getId());
    assertThat(instances, is(notNullValue()));
    assertThat(instances.size(), is(1));
    QuestionGroupInstance qGInst = instances.get(0);
    assertThat(qGInst.getVersionNum(), is(2));
    assertThat(qGInst.getEntityId(), is(101));
    assertThat(qGInst.getQuestionGroup().getId(), is(questionGroupDetail.getId()));
    List<QuestionGroupResponse> qGResponses = qGInst.getQuestionGroupResponses();
    assertThat(qGResponses, is(notNullValue()));
    assertThat(qGResponses.size(), is(2));
    assertThat(qGResponses.get(0).getResponse(), is("Hello World1"));
    assertThat(qGResponses.get(1).getResponse(), is("Hello World2"));
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)23 Test (org.junit.Test)15 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)13 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)11 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)6 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)3 Section (org.mifos.platform.questionnaire.domain.Section)3 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)3 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 SystemException (org.mifos.framework.exceptions.SystemException)1 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)1 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)1 QuestionGroupInstanceDetail (org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail)1