Search in sources :

Example 1 with ChoiceDto

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

the class QuestionnaireServiceFacadeTest method getQuestionDetail.

private QuestionDetail getQuestionDetail(int id, String text, QuestionType questionType, List<String> choices) {
    QuestionDetail questionDetail = new QuestionDetail(id, text, questionType, true, true);
    List<ChoiceDto> choiceDtos = new ArrayList<ChoiceDto>();
    for (String choice : choices) {
        choiceDtos.add(new ChoiceDto(choice));
    }
    questionDetail.setAnswerChoices(choiceDtos);
    return questionDetail;
}
Also used : ArrayList(java.util.ArrayList) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto)

Example 2 with ChoiceDto

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

the class SavingsAccountActionTest method getSectionDetail.

private SectionDetail getSectionDetail(String name, String title, List<String> answerChoices) {
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setName(name);
    QuestionDetail questionDetail = new QuestionDetail(111, title, QuestionType.SINGLE_SELECT, true, true);
    List<ChoiceDto> choiceDtos = new ArrayList<ChoiceDto>();
    for (String answerChoice : answerChoices) {
        choiceDtos.add(new ChoiceDto(answerChoice));
    }
    questionDetail.setAnswerChoices(choiceDtos);
    sectionDetail.setQuestionDetails(asList(new SectionQuestionDetail(questionDetail, true)));
    return sectionDetail;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 3 with ChoiceDto

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

the class QuestionnaireServiceTest method shouldDefineQuestionWithAnswerChoicesAndTags.

@Test
public void shouldDefineQuestionWithAnswerChoicesAndTags() throws SystemException {
    ChoiceDto choice1 = new ChoiceDto("choice1");
    choice1.setTags(asList("Tag1", "Tag2"));
    ChoiceDto choice2 = new ChoiceDto("choice2");
    choice2.setTags(asList("Tag3"));
    List<ChoiceDto> answerChoices = asList(choice1, choice2);
    QuestionDetail questionDefinition = new QuestionDetail(QUESTION_TITLE, QuestionType.MULTI_SELECT);
    questionDefinition.setAnswerChoices(answerChoices);
    try {
        QuestionDetail questionDetail = questionnaireService.defineQuestion(questionDefinition);
        verify(questionDao, times(1)).saveOrUpdate(any(QuestionEntity.class));
        Assert.assertNotNull(questionDetail);
        Assert.assertEquals(QUESTION_TITLE, questionDetail.getText());
        Assert.assertEquals(QuestionType.MULTI_SELECT, questionDetail.getType());
        Assert.assertEquals(choice1.getValue(), questionDetail.getAnswerChoices().get(0).getValue());
        Assert.assertEquals(choice1.getTags().get(0), questionDetail.getAnswerChoices().get(0).getTags().get(0));
        Assert.assertEquals(choice1.getTags().get(1), questionDetail.getAnswerChoices().get(0).getTags().get(1));
        Assert.assertEquals(choice2.getValue(), questionDetail.getAnswerChoices().get(1).getValue());
        Assert.assertEquals(choice2.getTags().get(0), questionDetail.getAnswerChoices().get(1).getTags().get(0));
    } catch (SystemException e) {
        Assert.fail("Should not have thrown the validation exception");
    }
    verify(questionnaireValidator).validateForDefineQuestion(questionDefinition);
    verify(questionDao).saveOrUpdate(any(QuestionEntity.class));
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 4 with ChoiceDto

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

the class QuestionnaireServiceTest method shouldSaveQuestionDto.

@Test
public void shouldSaveQuestionDto() {
    QuestionDtoBuilder questionDtoBuilder = new QuestionDtoBuilder();
    QuestionDto questionDto = questionDtoBuilder.withText("Ques1").withType(QuestionType.SMART_SELECT).addChoices(new ChoiceDto("Ch1"), new ChoiceDto("Ch2")).build();
    when(questionDao.create(any(QuestionEntity.class))).thenReturn(1234);
    Integer questionId = questionnaireService.defineQuestion(questionDto);
    assertThat(questionId, is(1234));
    verify(questionnaireValidator).validateForDefineQuestion(questionDto);
    verify(questionDao).create(any(QuestionEntity.class));
}
Also used : QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) Test(org.junit.Test)

Example 5 with ChoiceDto

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

the class QuestionDetailMatcher method matchesSafely.

@Override
public boolean matchesSafely(QuestionDetail questionDetail) {
    if (StringUtils.equals(questionDetail.getText(), this.questionDetail.getText()) && this.questionDetail.getType().equals(questionDetail.getType())) {
        List<ChoiceDto> choiceDtos = this.questionDetail.getAnswerChoices();
        for (int i = 0, choiceDetailsSize = choiceDtos.size(); i < choiceDetailsSize; i++) {
            ChoiceDto choiceDto = choiceDtos.get(i);
            assertEquals(choiceDto.getValue(), questionDetail.getAnswerChoices().get(i).getValue());
        }
        return true;
    }
    return false;
}
Also used : ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto)

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