Search in sources :

Example 16 with QuestionGroupDto

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_DifferentQuestionType_NoChoices.

@Test
public void shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_DifferentQuestionType_NoChoices() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    String questionTitle = questionGroupDto.getSections().get(0).getQuestions().get(0).getText();
    when(questionDao.retrieveByText(questionTitle)).thenReturn(asList(getQuestionEntity(questionTitle, AnswerType.DATE, 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_TITILE_MATCHES_EXISTING_QUESTION));
    }
}
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 17 with QuestionGroupDto

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_QuestionTitleExceedsMaxChars.

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

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateSectionName.

@Test
public void shouldValidateForInvalidQuestionGroupDto_DuplicateSectionName() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    questionGroupDto.getSections().get(0).setName(" Sec ");
    questionGroupDto.getSections().get(1).setName("sEc");
    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(QuestionnaireConstants.SECTION_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 19 with QuestionGroupDto

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingQuestionType.

@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingQuestionType() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    questionGroupDto.getSections().get(0).getQuestions().get(0).setType(QuestionType.INVALID);
    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(ANSWER_TYPE_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 20 with QuestionGroupDto

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

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