use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionnaireServiceTest method shouldSaveQuestionDto.
@Test
public void shouldSaveQuestionDto() {
QuestionDtoBuilder questionDtoBuilder = new QuestionDtoBuilder();
QuestionDto questionDto = questionDtoBuilder.withText("Ques1").withType(QuestionType.SMART_SELECT).addChoices(new ChoiceDto("Ch1"), new ChoiceDto("Ch2")).build();
when(questionDao.create(any(QuestionEntity.class))).thenReturn(1234);
Integer questionId = questionnaireService.defineQuestion(questionDto);
assertThat(questionId, is(1234));
verify(questionnaireValidator).validateForDefineQuestion(questionDto);
verify(questionDao).create(any(QuestionEntity.class));
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionnaireValidatorImpl method allQuestionsHaveUniqueOrders.
private boolean allQuestionsHaveUniqueOrders(List<QuestionDto> questions) {
boolean result = true;
Set<Integer> sectionOrders = new HashSet<Integer>();
for (QuestionDto question : questions) {
Integer order = question.getOrder();
if (sectionOrders.contains(order)) {
result = false;
break;
} else {
sectionOrders.add(order);
}
}
return result;
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionnaireMapperTest method shouldMapToQuestionGroupFromDto.
@Test
public void shouldMapToQuestionGroupFromDto() {
when(eventSourceDao.retrieveByEventAndSource("Create", "Client")).thenReturn(asList(getEventSourceEntity("Create", "Client")));
QuestionDto question1 = new QuestionDtoBuilder().withText("Ques1").withMandatory(true).withType(QuestionType.FREETEXT).withOrder(1).build();
ChoiceDto choice1 = new ChoiceDetailBuilder().withValue("Ch1").withOrder(1).build();
ChoiceDto choice2 = new ChoiceDetailBuilder().withValue("Ch2").withOrder(2).build();
ChoiceDto choice3 = new ChoiceDetailBuilder().withValue("Ch3").withOrder(3).build();
QuestionDto question2 = new QuestionDtoBuilder().withText("Ques2").withType(QuestionType.SINGLE_SELECT).addChoices(choice1, choice2, choice3).withOrder(2).build();
SectionDto section1 = new SectionDtoBuilder().withName("Sec1").withOrder(1).addQuestions(question1, question2).build();
QuestionGroupDto questionGroupDto = new QuestionGroupDtoBuilder().withTitle("QG1").withEventSource("Create", "Client").addSections(section1).build();
assertQuestionGroupEntity(questionnaireMapper.mapToQuestionGroup(questionGroupDto));
verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionGroupDefinitionParserTest method assertSecondSection.
private void assertSecondSection(SectionDto sectionDto) {
assertThat(sectionDto.getName(), is("misc"));
assertThat(sectionDto.getOrder(), is(2));
List<QuestionDto> questions = sectionDto.getQuestions();
assertThat(questions, is(notNullValue()));
assertThat(questions.size(), is(3));
QuestionDto questionDto = questions.get(0);
assertThat(questionDto.getNickname(), is("father_name"));
assertThat(questionDto.getText(), is("Father's name'"));
assertThat(questionDto.getType(), is(QuestionType.FREETEXT));
assertThat(questionDto.getOrder(), is(1));
questionDto = questions.get(1);
assertThat(questionDto.getNickname(), is("num_dependents"));
assertThat(questionDto.getText(), is("No of dependents"));
assertThat(questionDto.getType(), is(QuestionType.SINGLE_SELECT));
assertThat(questionDto.getOrder(), is(2));
assertThat(questionDto.isMandatory(), is(true));
List<ChoiceDto> choices = questionDto.getChoices();
assertThat(choices, is(notNullValue()));
assertThat(choices.size(), is(3));
assertChoiceDetail(choices.get(0), "Less than 2", 1);
assertChoiceDetail(choices.get(1), "Less than 5", 2);
assertChoiceDetail(choices.get(2), "Less than 10", 3);
questionDto = questions.get(2);
assertThat(questionDto.getNickname(), is("previous_loans"));
assertThat(questionDto.getText(), is("Previous Loans taken for"));
assertThat(questionDto.getType(), is(QuestionType.SMART_SELECT));
assertThat(questionDto.getOrder(), is(3));
assertThat(questionDto.isMandatory(), is(true));
choices = questionDto.getChoices();
assertThat(choices, is(notNullValue()));
assertThat(choices.size(), is(4));
assertFirstChoiceWithTags(choices.get(0));
assertSecondChoiceWithTags(choices.get(1));
assertThirdChoiceWithTags(choices.get(2));
assertFourthChoiceWithTags(choices.get(3));
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionGroupDefinitionParserTest method assertFirstSection.
private void assertFirstSection(SectionDto sectionDto) {
assertThat(sectionDto.getName(), is("default"));
assertThat(sectionDto.getOrder(), is(1));
List<QuestionDto> questions = sectionDto.getQuestions();
assertThat(questions, is(notNullValue()));
assertThat(questions.size(), is(2));
QuestionDto questionDto = questions.get(0);
assertThat(questionDto.getNickname(), is("date_of_birth"));
assertThat(questionDto.getText(), is("Your DOB"));
assertThat(questionDto.getType(), is(QuestionType.DATE));
assertThat(questionDto.getOrder(), is(1));
questionDto = questions.get(1);
assertThat(questionDto.getNickname(), is("num_family_members"));
assertThat(questionDto.getText(), is("How many family members"));
assertThat(questionDto.getType(), is(QuestionType.NUMERIC));
assertThat(questionDto.getOrder(), is(2));
assertThat(questionDto.getMinValue(), is(3));
assertThat(questionDto.getMaxValue(), is(10));
assertThat(questionDto.isMandatory(), is(true));
}
Aggregations