Search in sources :

Example 21 with ValidationException

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

the class QuestionnaireValidatorForDtoTest method shouldNotValidateForValidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithSimilarChoices.

@Test
public void shouldNotValidateForValidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithSimilarChoices() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    String questionTitle = questionGroupDto.getSections().get(0).getQuestions().get(1).getText();
    List<QuestionChoiceEntity> choices = asList(getChoice("Ch2"), getChoice("Ch3"), getChoice("cH1"));
    when(questionDao.retrieveByText(questionTitle)).thenReturn(asList(getQuestionEntity(questionTitle, AnswerType.SINGLESELECT, choices)));
    try {
        questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
    } catch (ValidationException e) {
        fail("Should not have thrown validationException");
    }
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) ValidationException(org.mifos.platform.validations.ValidationException) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Test(org.junit.Test)

Example 22 with ValidationException

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_QuestionGroupTitleExceedsMaxChars.

@Test
public void shouldValidateForInvalidQuestionGroupDto_QuestionGroupTitleExceedsMaxChars() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    questionGroupDto.setTitle("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(QUESTION_GROUP_TITLE_TOO_BIG));
    }
}
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 23 with ValidationException

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

the class UploadQuestionGroupControllerTest method testUploadQuestionGroup_UploadFailureDuringValidation.

@Test
public void testUploadQuestionGroup_UploadFailureDuringValidation() {
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
    validationException.addChildException(new ValidationException(QUESTION_GROUP_TITLE_NOT_PROVIDED));
    validationException.addChildException(new ValidationException(DUPLICATE_QUESTION_FOUND_IN_SECTION));
    doThrow(validationException).when(questionnaireServiceFacade).uploadPPIQuestionGroup("INDIA");
    UploadQuestionGroupForm form = new UploadQuestionGroupForm();
    form.setSelectedCountry("INDIA");
    String result = controller.upload(form, requestContext);
    assertThat(result, is("failure"));
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher(QUESTION_GROUP_TITLE_NOT_PROVIDED)));
    verify(messageContext).addMessage(argThat(new MessageMatcher(DUPLICATE_QUESTION_FOUND_IN_SECTION)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) ValidationException(org.mifos.platform.validations.ValidationException) UploadQuestionGroupForm(org.mifos.platform.questionnaire.ui.model.UploadQuestionGroupForm) Test(org.junit.Test)

Example 24 with ValidationException

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingSectionOrder.

@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingSectionOrder() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    questionGroupDto.getSections().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(SECTION_ORDER_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)

Example 25 with ValidationException

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingQuestionsInSection.

@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingQuestionsInSection() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    questionGroupDto.getSections().get(0).setQuestions(Collections.<QuestionDto>emptyList());
    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(NO_QUESTIONS_FOUND_IN_SECTION));
    }
}
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