use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionnaireServiceTest method shouldDefineQuestionWithAnswerChoicesAndTags.
@Test
public void shouldDefineQuestionWithAnswerChoicesAndTags() throws SystemException {
ChoiceDto choice1 = new ChoiceDto("choice1");
choice1.setTags(asList("Tag1", "Tag2"));
ChoiceDto choice2 = new ChoiceDto("choice2");
choice2.setTags(asList("Tag3"));
List<ChoiceDto> answerChoices = asList(choice1, choice2);
QuestionDetail questionDefinition = new QuestionDetail(QUESTION_TITLE, QuestionType.MULTI_SELECT);
questionDefinition.setAnswerChoices(answerChoices);
try {
QuestionDetail questionDetail = questionnaireService.defineQuestion(questionDefinition);
verify(questionDao, times(1)).saveOrUpdate(any(QuestionEntity.class));
Assert.assertNotNull(questionDetail);
Assert.assertEquals(QUESTION_TITLE, questionDetail.getText());
Assert.assertEquals(QuestionType.MULTI_SELECT, questionDetail.getType());
Assert.assertEquals(choice1.getValue(), questionDetail.getAnswerChoices().get(0).getValue());
Assert.assertEquals(choice1.getTags().get(0), questionDetail.getAnswerChoices().get(0).getTags().get(0));
Assert.assertEquals(choice1.getTags().get(1), questionDetail.getAnswerChoices().get(0).getTags().get(1));
Assert.assertEquals(choice2.getValue(), questionDetail.getAnswerChoices().get(1).getValue());
Assert.assertEquals(choice2.getTags().get(0), questionDetail.getAnswerChoices().get(1).getTags().get(0));
} catch (SystemException e) {
Assert.fail("Should not have thrown the validation exception");
}
verify(questionnaireValidator).validateForDefineQuestion(questionDefinition);
verify(questionDao).saveOrUpdate(any(QuestionEntity.class));
}
use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionnaireServiceTest method testGetSingleSelectQuestionById.
@Test
public void testGetSingleSelectQuestionById() throws SystemException {
int questionId = 1;
String title = "Title";
List<QuestionChoiceEntity> questionChoices = asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2"));
when(questionDao.getDetails(questionId)).thenReturn(getQuestion(questionId, title, AnswerType.SINGLESELECT, questionChoices));
QuestionDetail questionDetail = questionnaireService.getQuestion(questionId);
Assert.assertNotNull(questionDetail);
Assert.assertThat(questionDetail.getText(), is(title));
Assert.assertThat(questionDetail.getType(), is(QuestionType.SINGLE_SELECT));
Assert.assertEquals("choice1", questionDetail.getAnswerChoices().get(0).getValue());
Assert.assertEquals("choice2", questionDetail.getAnswerChoices().get(1).getValue());
verify(questionDao, times(1)).getDetails(questionId);
}
use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionnaireServiceTest method testGetMultiSelectQuestionById.
@Test
public void testGetMultiSelectQuestionById() throws SystemException {
int questionId = 1;
String title = "Title";
List<QuestionChoiceEntity> questionChoiceEntities = asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2"));
when(questionDao.getDetails(questionId)).thenReturn(getQuestion(questionId, title, AnswerType.MULTISELECT, questionChoiceEntities));
QuestionDetail questionDetail = questionnaireService.getQuestion(questionId);
Assert.assertNotNull(questionDetail);
assertThat(questionDetail.getText(), is(title));
assertThat(questionDetail.getType(), is(QuestionType.MULTI_SELECT));
Assert.assertEquals("choice1", questionDetail.getAnswerChoices().get(0).getValue());
Assert.assertEquals("choice2", questionDetail.getAnswerChoices().get(1).getValue());
verify(questionDao, times(1)).getDetails(questionId);
}
use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionnaireMapperImpl method mapToSectionDetail.
private SectionDetail mapToSectionDetail(Section section) {
SectionDetail sectionDetail = new SectionDetail();
sectionDetail.setId(section.getId());
sectionDetail.setName(section.getName());
if (section.getSequenceNumber() != null) {
sectionDetail.setSequenceNumber(section.getSequenceNumber());
}
for (SectionQuestion sectionQuestion : section.getQuestions()) {
QuestionEntity question = sectionQuestion.getQuestion();
QuestionType type = mapToQuestionType(question.getAnswerTypeAsEnum());
boolean required = sectionQuestion.isRequired();
QuestionDetail questionDetail = mapToQuestionDetail(question, type);
sectionDetail.addQuestion(mapToSectionQuestionDetail(sectionQuestion, required, sectionQuestion.isShowOnPage(), questionDetail));
}
return sectionDetail;
}
use of org.mifos.platform.questionnaire.service.QuestionDetail in project head by mifos.
the class QuestionnaireMapperImpl method mapToSectionQuestion.
private SectionQuestion mapToSectionQuestion(SectionQuestionDetail sectionQuestionDetail, int seqNum, Section section) {
QuestionDetail questionDetail = sectionQuestionDetail.getQuestionDetail();
SectionQuestion sectionQuestion = getSectionQuestion(questionDetail, section);
sectionQuestion.setRequired(sectionQuestionDetail.isMandatory());
sectionQuestion.setShowOnPage(sectionQuestionDetail.isShowOnPage());
sectionQuestion.setSequenceNumber(sectionQuestionDetail.getSequenceNumber());
if (sectionQuestion.isNewSectionQuestion()) {
sectionQuestion.setQuestion(mapToQuestion(questionDetail));
sectionQuestion.setSequenceNumber(seqNum);
sectionQuestion.setSection(section);
}
return sectionQuestion;
}
Aggregations