Search in sources :

Example 11 with QuestionGroupDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto 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 12 with QuestionGroupDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto 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 13 with QuestionGroupDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto 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)

Example 14 with QuestionGroupDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto in project head by mifos.

the class QuestionnaireValidatorForDtoTest method shouldValidateForValidQuestionGroupDto_DuplicateQuestionTitle.

@Test
public void shouldValidateForValidQuestionGroupDto_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");
    boolean withDuplicateQuestionTextCheck = false;
    questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto, withDuplicateQuestionTextCheck);
}
Also used : QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Test(org.junit.Test)

Example 15 with QuestionGroupDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto in project head by mifos.

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingQuestionTitle.

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

QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)40 Test (org.junit.Test)39 ValidationException (org.mifos.platform.validations.ValidationException)30 Arrays.asList (java.util.Arrays.asList)27 List (java.util.List)27 QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)4 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)3 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)3 SectionDto (org.mifos.platform.questionnaire.service.dtos.SectionDto)3 ChoiceDetailBuilder (org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder)2 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)2 QuestionGroupDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder)2 SectionDtoBuilder (org.mifos.platform.questionnaire.builders.SectionDtoBuilder)2 InputStream (java.io.InputStream)1 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Transactional (org.springframework.transaction.annotation.Transactional)1