Search in sources :

Example 11 with QuestionDto

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));
    }
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 12 with QuestionDto

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);
        }
    }
}
Also used : SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto)

Example 13 with QuestionDto

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));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 14 with QuestionDto

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;
}
Also used : QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) HashSet(java.util.HashSet)

Example 15 with QuestionDto

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);
}
Also used : QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) Test(org.junit.Test)

Aggregations

QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)15 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)8 Test (org.junit.Test)7 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)7 SectionDto (org.mifos.platform.questionnaire.service.dtos.SectionDto)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 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)4 Arrays.asList (java.util.Arrays.asList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ValidationException (org.mifos.platform.validations.ValidationException)2 BigInteger (java.math.BigInteger)1 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Transactional (org.springframework.transaction.annotation.Transactional)1