use of org.mifos.platform.questionnaire.service.SectionDetail 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()));
}
use of org.mifos.platform.questionnaire.service.SectionDetail 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"));
}
use of org.mifos.platform.questionnaire.service.SectionDetail 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"));
}
use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.
the class QuestionnaireValidatorTest method getSectionWithQuestions.
private SectionDetail getSectionWithQuestions(String name, int... questionIds) {
SectionDetail section = new SectionDetail();
section.setName(name);
if (questionIds != null) {
for (int questionId : questionIds) {
section.addQuestion(new SectionQuestionDetail(new QuestionDetail(questionId, null, QuestionType.INVALID, true, true), true, null));
}
}
return section;
}
use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.
the class QuestionnaireValidatorTest method shouldThrowExceptionWhenANumericQuestionHasAnswerMoreThanMax.
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldThrowExceptionWhenANumericQuestionHasAnswerMoreThanMax() {
QuestionDetail questionDetail = getNumericQuestionDetail("Numeric Question", null, 100);
SectionDetail sectionWithOneQuestion = getSectionWithOneQuestion("Sec1", questionDetail, "101");
QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(0, "Title", "Create", "Client", asList(sectionWithOneQuestion));
try {
questionnaireValidator.validateForQuestionGroupResponses(asList(questionGroupDetail));
fail("Should have thrown the validation exception");
} catch (ValidationException e) {
assertEquals(GENERIC_VALIDATION, e.getKey());
assertEquals(true, e.hasChildExceptions());
assertEquals(1, e.getChildExceptions().size());
ValidationException childException = e.getChildExceptions().get(0);
assertTrue(childException instanceof BadNumericResponseException);
assertEquals("Numeric Question", childException.getIdentifier());
assertNull(((BadNumericResponseException) childException).getAllowedMinValue());
assertEquals(Integer.valueOf(100), ((BadNumericResponseException) childException).getAllowedMaxValue());
}
}
Aggregations