Search in sources :

Example 1 with SectionDto

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

the class QuestionnaireValidatorImpl method allSectionsHaveUniqueNames.

private boolean allSectionsHaveUniqueNames(List<SectionDto> sections) {
    boolean result = true;
    Set<String> sectionNames = new HashSet<String>();
    for (SectionDto section : sections) {
        String name = section.getName().toLowerCase(Locale.getDefault());
        if (sectionNames.contains(name)) {
            result = false;
            break;
        } else {
            sectionNames.add(name);
        }
    }
    return result;
}
Also used : SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) HashSet(java.util.HashSet)

Example 2 with SectionDto

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

the class QuestionnaireMapperTest method shouldMapToQuestionGroupFromDto.

@Test
public void shouldMapToQuestionGroupFromDto() {
    when(eventSourceDao.retrieveByEventAndSource("Create", "Client")).thenReturn(asList(getEventSourceEntity("Create", "Client")));
    QuestionDto question1 = new QuestionDtoBuilder().withText("Ques1").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("Ques2").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("QG1").withEventSource("Create", "Client").addSections(section1).build();
    assertQuestionGroupEntity(questionnaireMapper.mapToQuestionGroup(questionGroupDto));
    verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
}
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)

Example 3 with SectionDto

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

the class QuestionGroupDefinitionParserTest method shouldParseQuestionDefinitionXml.

@Test
public void shouldParseQuestionDefinitionXml() throws Exception {
    QuestionGroupDefinitionParser questionGroupDefinitionParser = new QuestionGroupDefinitionParserImpl();
    String questionGroupDefXml = "/org/mifos/platform/questionnaire/QuestionGroupDefinition.xml";
    InputStream inputStream = getClass().getResourceAsStream(questionGroupDefXml);
    QuestionGroupDto questionGroupDto = questionGroupDefinitionParser.parse(inputStream);
    assertQuestionGroupDto(questionGroupDto);
    EventSourceDto eventSourceDto = questionGroupDto.getEventSourceDtos().get(0);
    assertEventSource(eventSourceDto);
    List<SectionDto> sectionDtos = questionGroupDto.getSections();
    assertSections(sectionDtos);
}
Also used : InputStream(java.io.InputStream) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 4 with SectionDto

use of org.mifos.platform.questionnaire.service.dtos.SectionDto 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 5 with SectionDto

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

Aggregations

SectionDto (org.mifos.platform.questionnaire.service.dtos.SectionDto)9 QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)6 ChoiceDetailBuilder (org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder)5 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)5 QuestionGroupDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder)5 SectionDtoBuilder (org.mifos.platform.questionnaire.builders.SectionDtoBuilder)5 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)5 Test (org.junit.Test)3 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)3 HashSet (java.util.HashSet)2 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)1 Transactional (org.springframework.transaction.annotation.Transactional)1