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