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));
}
}
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()))));
}
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));
}
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));
}
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"));
}
Aggregations