Search in sources :

Example 6 with QuestionGroupDto

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

the class QuestionnaireServiceIntegrationTest method shouldSaveQuestionGroupFromDto.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldSaveQuestionGroupFromDto() {
    String ques1Title = "Ques1" + currentTimeMillis();
    String ques2Title = "Ques2" + currentTimeMillis();
    String qgTitle = "QG1" + currentTimeMillis();
    createSingleSelectQuestion(ques2Title);
    QuestionDto question1 = new QuestionDtoBuilder().withText(ques1Title).withMandatory(true).withType(QuestionType.FREETEXT).withOrder(1).build();
    ChoiceDto choice1 = new ChoiceDetailBuilder().withValue("Ch1").withOrder(1).build();
    ChoiceDto choice2 = new ChoiceDetailBuilder().withValue("Ch2").withOrder(2).build();
    ChoiceDto choice3 = new ChoiceDetailBuilder().withValue("Ch3").withOrder(3).build();
    QuestionDto question2 = new QuestionDtoBuilder().withText(ques2Title).withType(QuestionType.SINGLE_SELECT).addChoices(choice1, choice2, choice3).withOrder(2).build();
    SectionDto section1 = new SectionDtoBuilder().withName("Sec1").withOrder(1).addQuestions(question1, question2).build();
    QuestionGroupDto questionGroupDto = new QuestionGroupDtoBuilder().withTitle(qgTitle).withEventSource("Create", "Client").addSections(section1).build();
    Integer questionGroupId = questionnaireService.defineQuestionGroup(questionGroupDto);
    assertQuestionGroup(questionGroupDao.getDetails(questionGroupId), qgTitle, ques1Title, ques2Title);
}
Also used : SectionDtoBuilder(org.mifos.platform.questionnaire.builders.SectionDtoBuilder) QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) ChoiceDetailBuilder(org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder) QuestionGroupDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with QuestionGroupDto

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

the class QuestionnaireServiceTest method shouldDefineQuestionGroupFromDto_WithExistingQuestions.

@Test
public void shouldDefineQuestionGroupFromDto_WithExistingQuestions() {
    QuestionEntity questionEntity = new QuestionEntity("Ques2");
    questionEntity.setAnswerType(AnswerType.SINGLESELECT);
    questionEntity.setChoices(asList(new QuestionChoiceEntity("Choice1"), new QuestionChoiceEntity("Choice2")));
    when(questionDao.retrieveByText("Ques2")).thenReturn(asList(questionEntity));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    questionnaireService.defineQuestionGroup(questionGroupDto);
    verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDto, true);
    verify(questionGroupDao).create(argThat(new QuestionGroupContainsQuestionMatcher(questionEntity)));
}
Also used : QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Test(org.junit.Test)

Example 8 with QuestionGroupDto

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionDto_MissingQuestionTitle.

@Test
public void shouldValidateForInvalidQuestionDto_MissingQuestionTitle() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    QuestionDto questionDto = questionGroupDto.getSections().get(0).getQuestions().get(0);
    questionDto.setText(null);
    try {
        questionnaireValidator.validateForDefineQuestion(questionDto);
        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) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 9 with QuestionGroupDto

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_DuplicateOrderForChoice.

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

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionDto_QuestionTitleExceedsMaxChars.

@Test
public void shouldValidateForInvalidQuestionDto_QuestionTitleExceedsMaxChars() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    QuestionDto questionDto = questionGroupDto.getSections().get(0).getQuestions().get(0);
    questionDto.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.validateForDefineQuestion(questionDto);
        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) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) 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