use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.
the class QuestionnaireServiceTest method getSectionDetailWithQuestions.
private SectionDetail getSectionDetailWithQuestions(String name, List<QuestionDetail> questionDetails, String value, boolean mandatory) {
SectionDetail sectionDetail = new SectionDetail();
sectionDetail.setName(name);
List<SectionQuestionDetail> sectionQuestionDetails = new ArrayList<SectionQuestionDetail>();
for (QuestionDetail questionDetail : questionDetails) {
SectionQuestionDetail sectionQuestionDetail = new SectionQuestionDetail(questionDetail, mandatory);
sectionQuestionDetail.setValue(value);
sectionQuestionDetails.add(sectionQuestionDetail);
}
sectionDetail.setQuestionDetails(sectionQuestionDetails);
return sectionDetail;
}
use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.
the class QuestionnaireServiceTest method testValidateResponse.
@Test
public void testValidateResponse() {
List<QuestionDetail> questionDetails = asList(new QuestionDetail(12, "Question 1", QuestionType.FREETEXT, true, true));
List<SectionDetail> sectionDetails = asList(getSectionDetailWithQuestions("Sec1", questionDetails, null, true));
QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(1, "QG1", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails, true);
try {
doThrow(new MandatoryAnswerNotFoundException("Title")).when(questionnaireValidator).validateForQuestionGroupResponses(asList(questionGroupDetail));
questionnaireService.validateResponses(asList(questionGroupDetail));
Assert.fail("Should not have thrown the validation exception");
} catch (ValidationException e) {
verify(questionnaireValidator, times(1)).validateForQuestionGroupResponses(asList(questionGroupDetail));
}
}
use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.
the class QuestionGroupInstanceDaoIntegrationTest method getSection.
private SectionDetail getSection(String name) throws SystemException {
SectionDetail section = new SectionDetail();
section.setName(name);
String questionTitle = "Question" + name + currentTimeMillis();
QuestionDetail questionDetail = defineQuestion(questionTitle, QuestionType.NUMERIC);
section.addQuestion(new SectionQuestionDetail(questionDetail, true));
return section;
}
use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.
the class QuestionGroupInstanceDaoIntegrationTest method shouldGetAllQuestionGroupInstancesByEntityAndEventSourceId.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldGetAllQuestionGroupInstancesByEntityAndEventSourceId() {
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, 1), getQuestionGroupInstance(2010, 7, 24, questionGroup2, 101, 1), getQuestionGroupInstance(2010, 7, 25, questionGroup2, 101, 1), getQuestionGroupInstance(2010, 7, 26, questionGroup2, 101, 1), getQuestionGroupInstance(2010, 7, 24, questionGroup3, 101, 1), getQuestionGroupInstance(2010, 7, 26, questionGroup3, 101, 1));
questionGroupInstanceDao.saveOrUpdateAll(questionGroupInstances);
int eventSourceId = (eventSourceDao.retrieveByEventAndSource("View", "Client").get(0)).getId();
List<QuestionGroupInstance> list = questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId);
assertThat(list, is(notNullValue()));
assertThat(list.size(), is(7));
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()));
assertThat((list.get(3)).getId(), is(questionGroupInstances.get(3).getId()));
assertThat((list.get(4)).getId(), is(questionGroupInstances.get(0).getId()));
assertThat((list.get(5)).getId(), is(questionGroupInstances.get(2).getId()));
assertThat((list.get(6)).getId(), is(questionGroupInstances.get(5).getId()));
}
use of org.mifos.platform.questionnaire.service.SectionDetail in project head by mifos.
the class SectionQuestionDaoIntegrationTest method shouldRetrieveSectionQuestionIdByQuestionGroupNameSectionNameQuestionId.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldRetrieveSectionQuestionIdByQuestionGroupNameSectionNameQuestionId() {
String title = "QG1" + currentTimeMillis();
SectionDetail sectionDetail1 = getSection("S1");
SectionDetail sectionDetail2 = getSection("S2");
List<SectionDetail> details = asList(sectionDetail1, sectionDetail2);
QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
Integer questionId = questionGroup.getSections().get(1).getQuestions().get(1).getQuestion().getQuestionId();
Integer sectionQuestionId = questionGroup.getSections().get(1).getQuestions().get(1).getId();
List<Integer> sectionQuestionIds = sectionQuestionDao.retrieveIdFromQuestionGroupIdQuestionIdSectionName("S2", questionId, questionGroup.getId());
assertThat(sectionQuestionIds, is(notNullValue()));
assertThat(sectionQuestionIds.size(), is(1));
assertThat(sectionQuestionIds.get(0), is(sectionQuestionId));
}
Aggregations