Search in sources :

Example 36 with QuestionGroupDto

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateQuestionOrder.

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

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateSectionOrder.

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

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingOrderForChoice.

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

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

the class QuestionnaireServiceTest method shouldDefineQuestionGroupFromDto.

@Test
public void shouldDefineQuestionGroupFromDto() {
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    questionnaireService.defineQuestionGroup(questionGroupDto);
    verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDto, true);
    verify(questionGroupDao).create(any(QuestionGroup.class));
}
Also used : QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Test(org.junit.Test)

Example 40 with QuestionGroupDto

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

the class QuestionnaireServiceTest method shouldDefineQuestionGroupFromDto_WithExistingQuestionTextMatchAndNicknameMismatch.

/*
     * If we pass try creating a question group with a question that has a unique nickname,
     * then a new question should be created even if the two questions are exactly the same.
     */
@Test
public void shouldDefineQuestionGroupFromDto_WithExistingQuestionTextMatchAndNicknameMismatch() {
    QuestionEntity newQuestionEntityFromDto = new QuestionEntity("Ques2");
    newQuestionEntityFromDto.setAnswerType(AnswerType.SINGLESELECT);
    newQuestionEntityFromDto.setNickname("Ques2_nick");
    newQuestionEntityFromDto.setChoices(asList(new QuestionChoiceEntity("Ch1"), new QuestionChoiceEntity("Ch2"), new QuestionChoiceEntity("Ch3")));
    QuestionEntity existingQuestionEntityWithMatchingName = new QuestionEntity("Ques2");
    existingQuestionEntityWithMatchingName.setAnswerType(AnswerType.SINGLESELECT);
    existingQuestionEntityWithMatchingName.setNickname("nick2");
    existingQuestionEntityWithMatchingName.setChoices(asList(new QuestionChoiceEntity("Ch1"), new QuestionChoiceEntity("Ch2"), new QuestionChoiceEntity("Ch3")));
    when(questionDao.retrieveByText("Ques2")).thenReturn(asList(existingQuestionEntityWithMatchingName));
    QuestionGroupDto questionGroupDto = getQuestionGroupDtoWithNicknames();
    questionnaireService.defineQuestionGroup(questionGroupDto);
    verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDto, true);
    verify(questionGroupDao).create(argThat(new QuestionGroupContainsQuestionNicknameMatcher(newQuestionEntityFromDto)));
}
Also used : 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