use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateOrderForChoice.
@Test
public void shouldValidateForInvalidQuestionGroupDto_DuplicateOrderForChoice() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).getQuestions().get(1).getChoices().get(0).setOrder(987);
questionGroupDto.getSections().get(0).getQuestions().get(1).getChoices().get(1).setOrder(987);
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 QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionDto_QuestionTitleExceedsMaxChars.
@Test
public void shouldValidateForInvalidQuestionDto_QuestionTitleExceedsMaxChars() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
QuestionDto questionDto = questionGroupDto.getSections().get(0).getQuestions().get(0);
questionDto.setText("there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "there are exactly fifty characters in this string " + "too much");
try {
questionnaireValidator.validateForDefineQuestion(questionDto);
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_TITLE_TOO_BIG));
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingValueForChoice.
@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingValueForChoice() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).getQuestions().get(1).getChoices().get(0).setValue(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.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateQuestionTitle.
@Test
public void shouldValidateForInvalidQuestionGroupDto_DuplicateQuestionTitle() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).getQuestions().get(0).setText(" Ques ");
questionGroupDto.getSections().get(0).getQuestions().get(1).setText("quEs");
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_TITLE_DUPLICATE));
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingTitle.
@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingTitle() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.setTitle(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_GROUP_TITLE_NOT_PROVIDED));
}
}
Aggregations