Search in sources :

Example 6 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity 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 7 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireMapperImpl method mapToChoice.

private QuestionChoiceEntity mapToChoice(ChoiceDto choice) {
    QuestionChoiceEntity choiceEntity = new QuestionChoiceEntity(choice.getValue());
    choiceEntity.setChoiceOrder(choice.getOrder());
    List<String> tags = choice.getTags();
    if (isNotEmpty(tags)) {
        Set<ChoiceTagEntity> choiceTagEntities = new LinkedHashSet<ChoiceTagEntity>();
        for (String tag : tags) {
            ChoiceTagEntity choiceTagEntity = new ChoiceTagEntity();
            choiceTagEntity.setTagText(tag);
            choiceTagEntities.add(choiceTagEntity);
        }
        choiceEntity.setTags(choiceTagEntities);
    }
    return choiceEntity;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) ChoiceTagEntity(org.mifos.platform.questionnaire.domain.ChoiceTagEntity)

Example 8 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithDifferentChoices.

@Test
public void shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithDifferentChoices() {
    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("Ch0"));
    when(questionDao.retrieveByText(questionTitle)).thenReturn(asList(getQuestionEntity(questionTitle, AnswerType.SINGLESELECT, choices)));
    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 : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) 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 9 with QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithDifferentNumberOfChoices.

@Test
public void shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithDifferentNumberOfChoices() {
    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("Ch5"));
    when(questionDao.retrieveByText(questionTitle)).thenReturn(asList(getQuestionEntity(questionTitle, AnswerType.SINGLESELECT, choices)));
    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 : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) 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 QuestionChoiceEntity

use of org.mifos.platform.questionnaire.domain.QuestionChoiceEntity in project head by mifos.

the class QuestionnaireMapperTest method shouldMapQuestionToQuestionDetail.

@Test
public void shouldMapQuestionToQuestionDetail() {
    QuestionEntity question = getQuestion(TITLE, AnswerType.FREETEXT);
    question.setQuestionState(QuestionState.INACTIVE);
    QuestionDetail questionDetail = questionnaireMapper.mapToQuestionDetail(question);
    assertQuestionDetail(questionDetail, TITLE, QuestionType.FREETEXT);
    assertThat(questionDetail.isActive(), is(false));
    question = getQuestion(TITLE, AnswerType.MULTISELECT, asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2")));
    question.setQuestionState(QuestionState.ACTIVE);
    questionDetail = questionnaireMapper.mapToQuestionDetail(question);
    assertQuestionDetail(questionDetail, TITLE, QuestionType.MULTI_SELECT, asList("choice1", "choice2"));
    assertThat(questionDetail.isActive(), is(true));
    question = getQuestion(TITLE, AnswerType.NUMBER);
    question.setNumericMin(10);
    question.setNumericMax(100);
    questionDetail = questionnaireMapper.mapToQuestionDetail(question);
    assertQuestionDetail(questionDetail, TITLE, QuestionType.NUMERIC);
    assertThat(questionDetail.getNumericMin(), is(10));
    assertThat(questionDetail.getNumericMax(), is(100));
    assertThat(questionDetail.isActive(), is(true));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Aggregations

QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)13 Test (org.junit.Test)8 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)7 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)4 ChoiceTagEntity (org.mifos.platform.questionnaire.domain.ChoiceTagEntity)3 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)3 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)3 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)3 ValidationException (org.mifos.platform.validations.ValidationException)3 Arrays.asList (java.util.Arrays.asList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Section (org.mifos.platform.questionnaire.domain.Section)2 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)2 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1