use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_SectionNameExceedsMaxChars.
@Test
public void shouldValidateForInvalidQuestionGroupDto_SectionNameExceedsMaxChars() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).setName("this is more than fifty characters string for question group title");
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_NAME_TOO_BIG));
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldNotValidateForValidQuestionGroupDto.
@Test
public void shouldNotValidateForValidQuestionGroupDto() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
try {
questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
} catch (ValidationException e) {
fail("Should not have thrown validationException");
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateValueForChoice.
@Test
public void shouldValidateForInvalidQuestionGroupDto_DuplicateValueForChoice() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).getQuestions().get(1).getChoices().get(0).setValue(" Choice");
questionGroupDto.getSections().get(0).getQuestions().get(1).getChoices().get(1).setValue("ChoICe ");
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.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorTest method shouldThrowExceptionWhenAMandatoryQuestionHasNoAnswer.
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldThrowExceptionWhenAMandatoryQuestionHasNoAnswer() {
QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(0, "Title", "Create", "Client");
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 MandatoryAnswerNotFoundException);
assertEquals("Q1", childException.getIdentifier());
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorTest method shouldThrowExceptionWhenANumericQuestionHasAnswerLessThanMin.
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldThrowExceptionWhenANumericQuestionHasAnswerLessThanMin() {
QuestionDetail questionDetail = getNumericQuestionDetail("Numeric Question", 10, null);
SectionDetail sectionWithOneQuestion = getSectionWithOneQuestion("Sec1", questionDetail, "9");
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());
assertEquals(Integer.valueOf(10), ((BadNumericResponseException) childException).getAllowedMinValue());
assertNull(((BadNumericResponseException) childException).getAllowedMaxValue());
}
}
Aggregations