Search in sources :

Example 11 with ChoiceDto

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

the class QuestionFormTest method testAddCurrentMultiSelectQuestion.

@Test
public void testAddCurrentMultiSelectQuestion() {
    QuestionForm questionForm = getQuestionForm("title", "multiSelect", "choice2");
    List<Question> questionList = questionForm.getQuestions();
    assertThat(questionList.size(), is(1));
    String text = questionList.get(0).getText();
    String type = questionList.get(0).getType();
    List<ChoiceDto> choices = questionList.get(0).getChoices();
    assertNotSame(type, questionForm.getCurrentQuestion().getType());
    assertNotSame(text, questionForm.getCurrentQuestion().getText());
    assertThat(type, is("multiSelect"));
    assertThat(text, is("title"));
    assertThat(choices.get(0).getValue(), is("choice2"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) Test(org.junit.Test)

Example 12 with ChoiceDto

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

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

the class QuestionGroupDefinitionParserTest method assertSecondSection.

private void assertSecondSection(SectionDto sectionDto) {
    assertThat(sectionDto.getName(), is("misc"));
    assertThat(sectionDto.getOrder(), is(2));
    List<QuestionDto> questions = sectionDto.getQuestions();
    assertThat(questions, is(notNullValue()));
    assertThat(questions.size(), is(3));
    QuestionDto questionDto = questions.get(0);
    assertThat(questionDto.getNickname(), is("father_name"));
    assertThat(questionDto.getText(), is("Father's name'"));
    assertThat(questionDto.getType(), is(QuestionType.FREETEXT));
    assertThat(questionDto.getOrder(), is(1));
    questionDto = questions.get(1);
    assertThat(questionDto.getNickname(), is("num_dependents"));
    assertThat(questionDto.getText(), is("No of dependents"));
    assertThat(questionDto.getType(), is(QuestionType.SINGLE_SELECT));
    assertThat(questionDto.getOrder(), is(2));
    assertThat(questionDto.isMandatory(), is(true));
    List<ChoiceDto> choices = questionDto.getChoices();
    assertThat(choices, is(notNullValue()));
    assertThat(choices.size(), is(3));
    assertChoiceDetail(choices.get(0), "Less than 2", 1);
    assertChoiceDetail(choices.get(1), "Less than 5", 2);
    assertChoiceDetail(choices.get(2), "Less than 10", 3);
    questionDto = questions.get(2);
    assertThat(questionDto.getNickname(), is("previous_loans"));
    assertThat(questionDto.getText(), is("Previous Loans taken for"));
    assertThat(questionDto.getType(), is(QuestionType.SMART_SELECT));
    assertThat(questionDto.getOrder(), is(3));
    assertThat(questionDto.isMandatory(), is(true));
    choices = questionDto.getChoices();
    assertThat(choices, is(notNullValue()));
    assertThat(choices.size(), is(4));
    assertFirstChoiceWithTags(choices.get(0));
    assertSecondChoiceWithTags(choices.get(1));
    assertThirdChoiceWithTags(choices.get(2));
    assertFourthChoiceWithTags(choices.get(3));
}
Also used : QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto)

Example 14 with ChoiceDto

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

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

ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)33 Test (org.junit.Test)14 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)13 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)11 QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)7 ArrayList (java.util.ArrayList)6 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)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 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)5 SectionDto (org.mifos.platform.questionnaire.service.dtos.SectionDto)5 Question (org.mifos.platform.questionnaire.ui.model.Question)5 QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)4 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)3 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)3 QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)3 HashSet (java.util.HashSet)2 SystemException (org.mifos.framework.exceptions.SystemException)2 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)2