Search in sources :

Example 11 with ValidationException

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));
    }
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 12 with ValidationException

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));
    }
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 13 with ValidationException

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));
    }
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 14 with ValidationException

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));
    }
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 15 with ValidationException

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));
    }
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Aggregations

ValidationException (org.mifos.platform.validations.ValidationException)58 Test (org.junit.Test)48 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)30 Arrays.asList (java.util.Arrays.asList)27 List (java.util.List)27 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)8 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)7 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)6 MandatoryAnswerNotFoundException (org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException)6 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)5 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)5 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 QuestionnaireServiceFacade (org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade)2 QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)2 MessageResolver (org.springframework.binding.message.MessageResolver)2 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionMessage (org.apache.struts.action.ActionMessage)1 Before (org.junit.Before)1