Search in sources :

Example 11 with SectionQuestion

use of org.mifos.platform.questionnaire.domain.SectionQuestion in project head by mifos.

the class QuestionnaireServiceIntegrationTest method assertQuestionGroup.

private void assertQuestionGroup(QuestionGroup questionGroup, String questionGroupTitle, String firstQuestionTitle, String secondQuestionTitle) {
    assertThat(questionGroup, is(notNullValue()));
    assertThat(questionGroup.getTitle(), is(questionGroupTitle));
    Set<EventSourceEntity> eventSources = questionGroup.getEventSources();
    assertThat(eventSources, is(notNullValue()));
    assertThat(eventSources.size(), is(1));
    EventSourceEntity eventSourceEntity = eventSources.toArray(new EventSourceEntity[eventSources.size()])[0];
    assertThat(eventSourceEntity.getEvent().getName(), is("Create"));
    assertThat(eventSourceEntity.getSource().getEntityType(), is("Client"));
    assertThat(questionGroup.getState(), is(QuestionGroupState.ACTIVE));
    List<Section> sections = questionGroup.getSections();
    assertThat(sections, is(notNullValue()));
    assertThat(sections.size(), is(1));
    Section section = sections.get(0);
    assertThat(section.getName(), is("Sec1"));
    List<SectionQuestion> questions = section.getQuestions();
    assertThat(questions, is(notNullValue()));
    assertThat(questions.size(), is(2));
    SectionQuestion sectionQuestion1 = questions.get(0);
    assertThat(sectionQuestion1.getSequenceNumber(), is(1));
    assertThat(sectionQuestion1.getSection(), is(notNullValue()));
    assertThat(sectionQuestion1.getSection().getName(), is("Sec1"));
    assertThat(sectionQuestion1.getSection().getSequenceNumber(), is(1));
    assertThat(sectionQuestion1.getQuestion(), is(notNullValue()));
    assertThat(sectionQuestion1.getQuestion().getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
    assertThat(sectionQuestion1.getQuestion().getQuestionText(), is(firstQuestionTitle));
    assertThat(sectionQuestion1.getQuestion().getAnswerTypeAsEnum(), is(AnswerType.FREETEXT));
    SectionQuestion sectionQuestion2 = questions.get(1);
    assertThat(sectionQuestion2.getSequenceNumber(), is(2));
    assertThat(sectionQuestion2.getSection(), is(notNullValue()));
    assertThat(sectionQuestion2.getSection().getName(), is("Sec1"));
    assertThat(sectionQuestion2.getSection().getSequenceNumber(), is(1));
    assertThat(sectionQuestion2.getQuestion(), is(notNullValue()));
    assertThat(sectionQuestion2.getQuestion().getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
    assertThat(sectionQuestion2.getQuestion().getQuestionText(), is(secondQuestionTitle));
    assertThat(sectionQuestion2.getQuestion().getAnswerTypeAsEnum(), is(AnswerType.SINGLESELECT));
    assertThat(sectionQuestion2.getQuestion().getChoices(), is(notNullValue()));
    assertThat(sectionQuestion2.getQuestion().getChoices().size(), is(3));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceText(), is("Ch2"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(0).getChoiceOrder(), is(1));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceText(), is("Ch1"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(1).getChoiceOrder(), is(2));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(2).getChoiceText(), is("Ch3"));
    assertThat(sectionQuestion2.getQuestion().getChoices().get(2).getChoiceOrder(), is(3));
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) Section(org.mifos.platform.questionnaire.domain.Section)

Example 12 with SectionQuestion

use of org.mifos.platform.questionnaire.domain.SectionQuestion in project head by mifos.

the class QuestionnaireMapperTest method assertSectionQuestions.

private void assertSectionQuestions(List<SectionQuestion> sectionQuestions) {
    assertThat(sectionQuestions, notNullValue());
    assertThat(sectionQuestions.size(), is(1));
    SectionQuestion sectionQuestion = sectionQuestions.get(0);
    assertThat(sectionQuestion.getQuestion(), notNullValue());
    assertThat(sectionQuestion.getSection(), notNullValue());
    assertThat(sectionQuestion.isRequired(), is(true));
    assertThat(sectionQuestion.getSequenceNumber(), is(0));
}
Also used : SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion)

Example 13 with SectionQuestion

use of org.mifos.platform.questionnaire.domain.SectionQuestion in project head by mifos.

the class QuestionnaireMapperTest method getSectionWithOneMultiSelectQuestion.

private Section getSectionWithOneMultiSelectQuestion(int sectionQuestionId, String sectionName, String questionName, String... choices) {
    Section section = new Section(sectionName);
    List<SectionQuestion> sectionQuestions = new ArrayList<SectionQuestion>();
    SectionQuestion sectionQuestion = new SectionQuestion();
    sectionQuestion.setId(sectionQuestionId);
    sectionQuestion.setSection(section);
    QuestionEntity questionEntity = new QuestionEntity();
    questionEntity.setQuestionText(questionName);
    questionEntity.setAnswerType(AnswerType.MULTISELECT);
    LinkedList<QuestionChoiceEntity> questionChoiceEntities = new LinkedList<QuestionChoiceEntity>();
    for (String choice : choices) {
        QuestionChoiceEntity questionChoiceEntity = new QuestionChoiceEntity();
        questionChoiceEntity.setChoiceText(choice);
        questionChoiceEntities.add(questionChoiceEntity);
    }
    questionEntity.setChoices(questionChoiceEntities);
    sectionQuestion.setQuestion(questionEntity);
    sectionQuestions.add(sectionQuestion);
    section.setQuestions(sectionQuestions);
    return section;
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Section(org.mifos.platform.questionnaire.domain.Section) LinkedList(java.util.LinkedList)

Example 14 with SectionQuestion

use of org.mifos.platform.questionnaire.domain.SectionQuestion in project head by mifos.

the class QuestionGroupDaoIntegrationTest method shouldRetrieveSectionQuestionIdByQuestionGroupNameSectionNameQuestionId.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldRetrieveSectionQuestionIdByQuestionGroupNameSectionNameQuestionId() {
    String title = "QG1" + currentTimeMillis();
    SectionDetail sectionDetail1 = getSection("S1");
    SectionDetail sectionDetail2 = getSection("S2");
    List<SectionDetail> details = asList(sectionDetail1, sectionDetail2);
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    List<Section> sections = questionGroupDao.retrieveSectionByNameAndQuestionGroupId("S2", questionGroupDetail.getId());
    assertThat(sections, is(notNullValue()));
    assertThat(sections.size(), is(1));
    Section section2 = sections.get(0);
    assertThat(section2.getName(), is("S2"));
    List<SectionQuestion> sections2Questions = section2.getQuestions();
    assertThat(sections2Questions, is(notNullValue()));
    assertThat(sections2Questions.size(), is(3));
    assertThat(sections2Questions.get(0).getQuestionText(), is(sectionDetail2.getQuestionDetail(0).getText()));
    assertThat(sections2Questions.get(1).getQuestionText(), is(sectionDetail2.getQuestionDetail(1).getText()));
    assertThat(sections2Questions.get(2).getQuestionText(), is(sectionDetail2.getQuestionDetail(2).getText()));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Section(org.mifos.platform.questionnaire.domain.Section) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with SectionQuestion

use of org.mifos.platform.questionnaire.domain.SectionQuestion in project head by mifos.

the class QuestionGroupInstanceDaoIntegrationTest method getQuestionGroupInstance.

private QuestionGroupInstance getQuestionGroupInstance(int version, QuestionGroup questionGroup, int entityId, String... responses) {
    QuestionGroupInstance questionGroupInstance = new QuestionGroupInstance();
    questionGroupInstance.setCompletedStatus(1);
    questionGroupInstance.setQuestionGroup(questionGroup);
    questionGroupInstance.setDateConducted(Calendar.getInstance().getTime());
    questionGroupInstance.setCreatorId(122);
    questionGroupInstance.setVersionNum(version);
    questionGroupInstance.setEntityId(entityId);
    List<QuestionGroupResponse> questionGroupResponses = new ArrayList<QuestionGroupResponse>();
    for (int index = 0; index < responses.length; index++) {
        SectionQuestion sectionQuestion = questionGroup.getSections().get(index).getQuestions().get(0);
        questionGroupResponses.add(getQuestionGroupResponse(responses[index], questionGroupInstance, sectionQuestion));
    }
    questionGroupInstance.setQuestionGroupResponses(questionGroupResponses);
    return questionGroupInstance;
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) ArrayList(java.util.ArrayList)

Aggregations

SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)20 Section (org.mifos.platform.questionnaire.domain.Section)7 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)5 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)5 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)4 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)4 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)4 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)3 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)3 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)3 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)3 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 Transactional (org.springframework.transaction.annotation.Transactional)2 LinkedList (java.util.LinkedList)1 SectionLink (org.mifos.platform.questionnaire.domain.SectionLink)1 SectionQuestionLink (org.mifos.platform.questionnaire.domain.SectionQuestionLink)1 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)1