Search in sources :

Example 26 with ChoiceDto

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

the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingRequiredNumberOfChoicesForSingleSelect.

@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingRequiredNumberOfChoicesForSingleSelect() {
    when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    questionGroupDto.getSections().get(0).getQuestions().get(1).setChoices(asList(new ChoiceDto("Ch1")));
    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_INSUFFICIENT));
    }
}
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) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) Test(org.junit.Test)

Example 27 with ChoiceDto

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

the class QuestionnaireMapperTest method shouldMapSingleSelectQuestionDetailToQuestion.

@Test
public void shouldMapSingleSelectQuestionDetailToQuestion() {
    ChoiceDto choice1 = new ChoiceDto("choice1");
    ChoiceDto choice2 = new ChoiceDto("choice2");
    QuestionDetail questionDefinition = new QuestionDetail(TITLE, QuestionType.SINGLE_SELECT);
    questionDefinition.setAnswerChoices(asList(choice1, choice2));
    QuestionEntity question = questionnaireMapper.mapToQuestion(questionDefinition);
    assertThat(question.getAnswerTypeAsEnum(), is(AnswerType.SINGLESELECT));
    assertThat(question.getQuestionText(), is(TITLE));
    assertThat(question.getChoices(), new QuestionChoicesMatcher(asList(new QuestionChoiceEntity(choice1.getValue()), new QuestionChoiceEntity(choice2.getValue()))));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test)

Example 28 with ChoiceDto

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

the class QuestionnaireMapperTest method shouldMapMultiSelectQuestionDetailToQuestion.

@Test
public void shouldMapMultiSelectQuestionDetailToQuestion() {
    ChoiceDto choice1 = new ChoiceDto("choice1");
    ChoiceDto choice2 = new ChoiceDto("choice2");
    QuestionDetail questionDefinition = new QuestionDetail(TITLE, QuestionType.MULTI_SELECT);
    questionDefinition.setAnswerChoices(asList(choice1, choice2));
    QuestionEntity question = questionnaireMapper.mapToQuestion(questionDefinition);
    assertThat(question.getAnswerTypeAsEnum(), is(AnswerType.MULTISELECT));
    assertThat(question.getQuestionText(), is(TITLE));
    assertThat(question.getChoices(), new QuestionChoicesMatcher(asList(new QuestionChoiceEntity(choice1.getValue()), new QuestionChoiceEntity(choice2.getValue()))));
    assertThat(question.getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test)

Example 29 with ChoiceDto

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

the class QuestionnaireMapperTest method shouldMapSmartSelectQuestionDetailToQuestion.

@Test
public void shouldMapSmartSelectQuestionDetailToQuestion() {
    ChoiceDto choice1 = new ChoiceDto("choice1");
    choice1.setTags(asList("Tag1", "Tag2"));
    ChoiceDto choice2 = new ChoiceDto("choice2");
    choice2.setTags(asList("Tag3"));
    QuestionDetail questionDefinition = new QuestionDetail(TITLE, QuestionType.SMART_SELECT);
    questionDefinition.setActive(true);
    questionDefinition.setAnswerChoices(asList(choice1, choice2));
    QuestionEntity question = questionnaireMapper.mapToQuestion(questionDefinition);
    assertThat(question.getAnswerTypeAsEnum(), is(AnswerType.SMARTSELECT));
    assertThat(question.getQuestionText(), is(TITLE));
    assertThat(question.getChoices(), new QuestionChoicesMatcher(asList(getChoiceEntity("choice1", "Tag1", "Tag2"), getChoiceEntity("choice2", "Tag3"))));
    assertThat(question.getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test)

Example 30 with ChoiceDto

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

the class QuestionControllerTest method testAddQuestionWhenTitleIsEdited.

@Test
public void testAddQuestionWhenTitleIsEdited() throws Exception {
    Question currentQuestion = new Question();
    QuestionDetail questionDetail = new QuestionDetail();
    questionDetail.setText(TITLE);
    questionDetail.setType(QuestionType.SINGLE_SELECT);
    questionDetail.setAnswerChoices(new ArrayList<ChoiceDto>(Arrays.asList(new ChoiceDto("choice1"), new ChoiceDto("choice2"))));
    currentQuestion.setQuestionDetail(questionDetail);
    currentQuestion.setCurrentChoice("choice3");
    currentQuestion.addAnswerChoice();
    QuestionForm questionForm = new QuestionForm();
    questionForm.setCurrentQuestion(currentQuestion);
    questionForm.getCurrentQuestion().setText(TITLE + 1);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE + 1)).thenReturn(false);
    String result = questionController.addQuestion(questionForm, requestContext, false);
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
    Assert.assertThat(questionForm.getQuestions().get(0).getInitialNumberOfChoices(), is(2));
    Assert.assertThat(questionForm.getQuestions().get(0).getChoices().size(), is(3));
    Assert.assertThat(result, is("success"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Aggregations

ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)33 Test (org.junit.Test)14 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)13 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)11 QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)7 ArrayList (java.util.ArrayList)6 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)6 ChoiceDetailBuilder (org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder)5 QuestionGroupDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder)5 SectionDtoBuilder (org.mifos.platform.questionnaire.builders.SectionDtoBuilder)5 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)5 SectionDto (org.mifos.platform.questionnaire.service.dtos.SectionDto)5 Question (org.mifos.platform.questionnaire.ui.model.Question)5 QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)4 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)3 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)3 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)3 HashSet (java.util.HashSet)2 SystemException (org.mifos.framework.exceptions.SystemException)2 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)2