use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateQuestionOrder.
@Test
public void shouldValidateForInvalidQuestionGroupDto_DuplicateQuestionOrder() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).getQuestions().get(0).setOrder(123);
questionGroupDto.getSections().get(0).getQuestions().get(1).setOrder(123);
try {
questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
fail("Should have thrown validationException");
} catch (ValidationException e) {
assertThat(e.getKey(), is(GENERIC_VALIDATION));
assertThat(e.hasChildExceptions(), is(true));
List<ValidationException> childExceptions = e.getChildExceptions();
assertThat(childExceptions, is(notNullValue()));
assertThat(childExceptions.size(), is(1));
assertThat(childExceptions.get(0).getKey(), is(QUESTION_ORDER_DUPLICATE));
}
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateSectionOrder.
@Test
public void shouldValidateForInvalidQuestionGroupDto_DuplicateSectionOrder() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).setOrder(21);
questionGroupDto.getSections().get(1).setOrder(21);
try {
questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
fail("Should have thrown validationException");
} catch (ValidationException e) {
assertThat(e.getKey(), is(GENERIC_VALIDATION));
assertThat(e.hasChildExceptions(), is(true));
List<ValidationException> childExceptions = e.getChildExceptions();
assertThat(childExceptions, is(notNullValue()));
assertThat(childExceptions.size(), is(1));
assertThat(childExceptions.get(0).getKey(), is(SECTION_ORDER_DUPLICATE));
}
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingOrderForChoice.
@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingOrderForChoice() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).getQuestions().get(1).getChoices().get(0).setOrder(null);
try {
questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
fail("Should have thrown validationException");
} catch (ValidationException e) {
assertThat(e.getKey(), is(GENERIC_VALIDATION));
assertThat(e.hasChildExceptions(), is(true));
List<ValidationException> childExceptions = e.getChildExceptions();
assertThat(childExceptions, is(notNullValue()));
assertThat(childExceptions.size(), is(1));
assertThat(childExceptions.get(0).getKey(), is(QUESTION_CHOICES_INVALID));
}
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto in project head by mifos.
the class QuestionnaireServiceTest method shouldDefineQuestionGroupFromDto.
@Test
public void shouldDefineQuestionGroupFromDto() {
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionnaireService.defineQuestionGroup(questionGroupDto);
verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDto, true);
verify(questionGroupDao).create(any(QuestionGroup.class));
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto in project head by mifos.
the class QuestionnaireServiceTest method shouldDefineQuestionGroupFromDto_WithExistingQuestionTextMatchAndNicknameMismatch.
/*
* If we pass try creating a question group with a question that has a unique nickname,
* then a new question should be created even if the two questions are exactly the same.
*/
@Test
public void shouldDefineQuestionGroupFromDto_WithExistingQuestionTextMatchAndNicknameMismatch() {
QuestionEntity newQuestionEntityFromDto = new QuestionEntity("Ques2");
newQuestionEntityFromDto.setAnswerType(AnswerType.SINGLESELECT);
newQuestionEntityFromDto.setNickname("Ques2_nick");
newQuestionEntityFromDto.setChoices(asList(new QuestionChoiceEntity("Ch1"), new QuestionChoiceEntity("Ch2"), new QuestionChoiceEntity("Ch3")));
QuestionEntity existingQuestionEntityWithMatchingName = new QuestionEntity("Ques2");
existingQuestionEntityWithMatchingName.setAnswerType(AnswerType.SINGLESELECT);
existingQuestionEntityWithMatchingName.setNickname("nick2");
existingQuestionEntityWithMatchingName.setChoices(asList(new QuestionChoiceEntity("Ch1"), new QuestionChoiceEntity("Ch2"), new QuestionChoiceEntity("Ch3")));
when(questionDao.retrieveByText("Ques2")).thenReturn(asList(existingQuestionEntityWithMatchingName));
QuestionGroupDto questionGroupDto = getQuestionGroupDtoWithNicknames();
questionnaireService.defineQuestionGroup(questionGroupDto);
verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDto, true);
verify(questionGroupDao).create(argThat(new QuestionGroupContainsQuestionNicknameMatcher(newQuestionEntityFromDto)));
}
Aggregations