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