Search in sources :

Example 6 with QuestionDetail

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

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

the class QuestionnaireServiceTest method testGetSingleSelectQuestionById.

@Test
public void testGetSingleSelectQuestionById() throws SystemException {
    int questionId = 1;
    String title = "Title";
    List<QuestionChoiceEntity> questionChoices = asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2"));
    when(questionDao.getDetails(questionId)).thenReturn(getQuestion(questionId, title, AnswerType.SINGLESELECT, questionChoices));
    QuestionDetail questionDetail = questionnaireService.getQuestion(questionId);
    Assert.assertNotNull(questionDetail);
    Assert.assertThat(questionDetail.getText(), is(title));
    Assert.assertThat(questionDetail.getType(), is(QuestionType.SINGLE_SELECT));
    Assert.assertEquals("choice1", questionDetail.getAnswerChoices().get(0).getValue());
    Assert.assertEquals("choice2", questionDetail.getAnswerChoices().get(1).getValue());
    verify(questionDao, times(1)).getDetails(questionId);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 8 with QuestionDetail

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

the class QuestionnaireServiceTest method testGetMultiSelectQuestionById.

@Test
public void testGetMultiSelectQuestionById() throws SystemException {
    int questionId = 1;
    String title = "Title";
    List<QuestionChoiceEntity> questionChoiceEntities = asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2"));
    when(questionDao.getDetails(questionId)).thenReturn(getQuestion(questionId, title, AnswerType.MULTISELECT, questionChoiceEntities));
    QuestionDetail questionDetail = questionnaireService.getQuestion(questionId);
    Assert.assertNotNull(questionDetail);
    assertThat(questionDetail.getText(), is(title));
    assertThat(questionDetail.getType(), is(QuestionType.MULTI_SELECT));
    Assert.assertEquals("choice1", questionDetail.getAnswerChoices().get(0).getValue());
    Assert.assertEquals("choice2", questionDetail.getAnswerChoices().get(1).getValue());
    verify(questionDao, times(1)).getDetails(questionId);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 9 with QuestionDetail

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

the class QuestionnaireMapperImpl method mapToSectionDetail.

private SectionDetail mapToSectionDetail(Section section) {
    SectionDetail sectionDetail = new SectionDetail();
    sectionDetail.setId(section.getId());
    sectionDetail.setName(section.getName());
    if (section.getSequenceNumber() != null) {
        sectionDetail.setSequenceNumber(section.getSequenceNumber());
    }
    for (SectionQuestion sectionQuestion : section.getQuestions()) {
        QuestionEntity question = sectionQuestion.getQuestion();
        QuestionType type = mapToQuestionType(question.getAnswerTypeAsEnum());
        boolean required = sectionQuestion.isRequired();
        QuestionDetail questionDetail = mapToQuestionDetail(question, type);
        sectionDetail.addQuestion(mapToSectionQuestionDetail(sectionQuestion, required, sectionQuestion.isShowOnPage(), questionDetail));
    }
    return sectionDetail;
}
Also used : SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionType(org.mifos.platform.questionnaire.service.QuestionType) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 10 with QuestionDetail

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

the class QuestionnaireMapperImpl method mapToSectionQuestion.

private SectionQuestion mapToSectionQuestion(SectionQuestionDetail sectionQuestionDetail, int seqNum, Section section) {
    QuestionDetail questionDetail = sectionQuestionDetail.getQuestionDetail();
    SectionQuestion sectionQuestion = getSectionQuestion(questionDetail, section);
    sectionQuestion.setRequired(sectionQuestionDetail.isMandatory());
    sectionQuestion.setShowOnPage(sectionQuestionDetail.isShowOnPage());
    sectionQuestion.setSequenceNumber(sectionQuestionDetail.getSequenceNumber());
    if (sectionQuestion.isNewSectionQuestion()) {
        sectionQuestion.setQuestion(mapToQuestion(questionDetail));
        sectionQuestion.setSequenceNumber(seqNum);
        sectionQuestion.setSection(section);
    }
    return sectionQuestion;
}
Also used : SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Aggregations

QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)72 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)55 Test (org.junit.Test)44 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)24 Question (org.mifos.platform.questionnaire.ui.model.Question)16 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)13 ArrayList (java.util.ArrayList)11 SystemException (org.mifos.framework.exceptions.SystemException)11 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)9 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)8 ValidationException (org.mifos.platform.validations.ValidationException)5 QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)4 Matchers.anyString (org.mockito.Matchers.anyString)4 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)3 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)3 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)3 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)2