use of org.mifos.platform.questionnaire.service.dtos.QuestionDto 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));
}
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionnaireServiceImpl method activateQGWithQuestions.
private void activateQGWithQuestions(QuestionGroupDto questionGroupDto) {
questionGroupDto.setActive(true);
for (SectionDto section : questionGroupDto.getSections()) {
for (QuestionDto question : section.getQuestions()) {
question.setActive(true);
question.setEditable(true);
}
}
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionnaireMapperTest method shouldMapQuestionDtoToQuestionEntity.
@Test
public void shouldMapQuestionDtoToQuestionEntity() {
String text = "question";
String nickname = "nickname";
QuestionDto questionDto = new QuestionDtoBuilder().withText(text).withNickname(nickname).withMandatory(true).withType(QuestionType.FREETEXT).withOrder(1).build();
QuestionEntity questionEntity = questionnaireMapper.mapToQuestion(questionDto);
assertThat(questionEntity.getQuestionText(), is(text));
assertThat(questionEntity.getNickname(), is(nickname));
assertThat(questionEntity.getAnswerTypeAsEnum(), is(AnswerType.FREETEXT));
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionnaireValidatorImpl method allQuestionsHaveUniqueNames.
private boolean allQuestionsHaveUniqueNames(List<QuestionDto> questions) {
boolean result = true;
Set<String> questionNames = new HashSet<String>();
for (QuestionDto question : questions) {
String name = question.getText().toLowerCase(Locale.getDefault());
if (questionNames.contains(name)) {
result = false;
break;
} else {
questionNames.add(name);
}
}
return result;
}
use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.
the class QuestionnaireServiceFacadeTest method testSaveQuestionDto.
@Test
public void testSaveQuestionDto() {
QuestionDtoBuilder questionDtoBuilder = new QuestionDtoBuilder();
QuestionDto questionDto = questionDtoBuilder.withText("Ques1").withType(QuestionType.FREETEXT).build();
when(questionnaireService.defineQuestion(questionDto)).thenReturn(1234);
Integer questionId = questionnaireServiceFacade.createQuestion(questionDto);
assertThat(questionId, is(1234));
verify(questionnaireService).defineQuestion(questionDto);
}
Aggregations