Search in sources :

Example 51 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class ValidationExceptionMessageExtractorTest method testMandatoryAnswerNotFoundException.

@Test
public void testMandatoryAnswerNotFoundException() {
    MandatoryAnswerNotFoundException e = new MandatoryAnswerNotFoundException("Title");
    ValidationException parent = new ValidationException("Key");
    parent.addChildException(e);
    ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor();
    extractor.extract(context, parent);
    verify(context).addMessage(any(MessageResolver.class));
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) MessageResolver(org.springframework.binding.message.MessageResolver) MandatoryAnswerNotFoundException(org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException) Test(org.junit.Test)

Example 52 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireServiceTest method testValidateResponse.

@Test
public void testValidateResponse() {
    List<QuestionDetail> questionDetails = asList(new QuestionDetail(12, "Question 1", QuestionType.FREETEXT, true, true));
    List<SectionDetail> sectionDetails = asList(getSectionDetailWithQuestions("Sec1", questionDetails, null, true));
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(1, "QG1", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails, true);
    try {
        doThrow(new MandatoryAnswerNotFoundException("Title")).when(questionnaireValidator).validateForQuestionGroupResponses(asList(questionGroupDetail));
        questionnaireService.validateResponses(asList(questionGroupDetail));
        Assert.fail("Should not have thrown the validation exception");
    } catch (ValidationException e) {
        verify(questionnaireValidator, times(1)).validateForQuestionGroupResponses(asList(questionGroupDetail));
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ValidationException(org.mifos.platform.validations.ValidationException) MandatoryAnswerNotFoundException(org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 53 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireValidatorImpl method questionsHaveInvalidOrders.

private boolean questionsHaveInvalidOrders(List<QuestionDto> questions, ValidationException parentException) {
    boolean invalid = false;
    if (!allQuestionsHaveOrders(questions)) {
        parentException.addChildException(new ValidationException(QUESTION_ORDER_NOT_PROVIDED));
        invalid = true;
    } else if (!allQuestionsHaveUniqueOrders(questions)) {
        parentException.addChildException(new ValidationException(QUESTION_ORDER_DUPLICATE));
        invalid = true;
    }
    return invalid;
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException)

Example 54 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireValidatorImpl method questionsHaveInvalidNames.

private boolean questionsHaveInvalidNames(List<QuestionDto> questions, ValidationException parentException, boolean withDuplicateQuestionTextCheck) {
    boolean invalid = false;
    if (!allQuestionsHaveNames(questions)) {
        parentException.addChildException(new ValidationException(QUESTION_TEXT_NOT_PROVIDED));
        invalid = true;
    } else if (withDuplicateQuestionTextCheck && !allQuestionsHaveUniqueNames(questions)) {
        parentException.addChildException(new ValidationException(QUESTION_TITLE_DUPLICATE));
        invalid = true;
    }
    return invalid;
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException)

Example 55 with ValidationException

use of org.mifos.platform.validations.ValidationException in project head by mifos.

the class QuestionnaireValidatorImpl method validateForDefineQuestion.

@Override
public void validateForDefineQuestion(QuestionDto questionDto) {
    ValidationException parentException = new ValidationException(GENERIC_VALIDATION);
    validateQuestion(questionDto, parentException, false, true);
    if (parentException.hasChildExceptions()) {
        throw parentException;
    }
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException)

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