Search in sources :

Example 6 with QuestionDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.

the class QuestionnaireServiceTest method getQuestionGroupDtoWithNicknames.

private QuestionGroupDto getQuestionGroupDtoWithNicknames() {
    QuestionDto question1 = new QuestionDtoBuilder().withText("Ques1").withNickname("Ques1_nick").withMandatory(true).withType(QuestionType.FREETEXT).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("Ques2").withNickname("Ques2_nick").withType(QuestionType.SINGLE_SELECT).addChoices(choice1, choice2, choice3).build();
    SectionDto section = new SectionDtoBuilder().withName("Sec1").withOrder(1).addQuestions(question1, question2).build();
    return new QuestionGroupDtoBuilder().withTitle("QG1").withEventSource("Create", "Client").addSections(section).build();
}
Also used : SectionDtoBuilder(org.mifos.platform.questionnaire.builders.SectionDtoBuilder) QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) ChoiceDetailBuilder(org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder) QuestionGroupDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder)

Example 7 with QuestionDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionDto 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);
}
Also used : SectionDtoBuilder(org.mifos.platform.questionnaire.builders.SectionDtoBuilder) QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) ChoiceDetailBuilder(org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder) QuestionGroupDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with QuestionDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.

the class QuestionnaireServiceTest method getQuestionGroupDto.

private QuestionGroupDto getQuestionGroupDto() {
    QuestionDto question1 = new QuestionDtoBuilder().withText("Ques1").withMandatory(true).withType(QuestionType.FREETEXT).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("Ques2").withType(QuestionType.SINGLE_SELECT).addChoices(choice1, choice2, choice3).build();
    SectionDto section = new SectionDtoBuilder().withName("Sec1").withOrder(1).addQuestions(question1, question2).build();
    return new QuestionGroupDtoBuilder().withTitle("QG1").withEventSource("Create", "Client").addSections(section).build();
}
Also used : SectionDtoBuilder(org.mifos.platform.questionnaire.builders.SectionDtoBuilder) QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) ChoiceDetailBuilder(org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder) QuestionGroupDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder)

Example 9 with QuestionDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionDto in project head by mifos.

the class QuestionnaireValidatorForDtoTest method getQuestionGroupDto.

private QuestionGroupDto getQuestionGroupDto() {
    String ques1Title = "Ques1" + currentTimeMillis();
    String ques2Title = "Ques2" + currentTimeMillis();
    String ques3Title = "Ques3" + currentTimeMillis();
    String ques4Title = "Ques4" + currentTimeMillis();
    String qgTitle = "QG1" + currentTimeMillis();
    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();
    QuestionDto question3 = new QuestionDtoBuilder().withText(ques3Title).withMandatory(false).withType(QuestionType.DATE).withOrder(1).build();
    QuestionDto question4 = new QuestionDtoBuilder().withText(ques4Title).withMandatory(true).withType(QuestionType.NUMERIC).withOrder(2).build();
    SectionDto section2 = new SectionDtoBuilder().withName("Sec2").withOrder(2).addQuestions(question3, question4).build();
    return new QuestionGroupDtoBuilder().withTitle(qgTitle).withEventSource("Create", "Client").addSections(section1, section2).build();
}
Also used : SectionDtoBuilder(org.mifos.platform.questionnaire.builders.SectionDtoBuilder) QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) ChoiceDetailBuilder(org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder) QuestionGroupDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder)

Example 10 with QuestionDto

use of org.mifos.platform.questionnaire.service.dtos.QuestionDto 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));
    }
}
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)

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