Search in sources :

Example 16 with QuestionEntity

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

the class QuestionnaireMapperTest method shouldMapSingleSelectQuestionDetailToQuestion.

@Test
public void shouldMapSingleSelectQuestionDetailToQuestion() {
    ChoiceDto choice1 = new ChoiceDto("choice1");
    ChoiceDto choice2 = new ChoiceDto("choice2");
    QuestionDetail questionDefinition = new QuestionDetail(TITLE, QuestionType.SINGLE_SELECT);
    questionDefinition.setAnswerChoices(asList(choice1, choice2));
    QuestionEntity question = questionnaireMapper.mapToQuestion(questionDefinition);
    assertThat(question.getAnswerTypeAsEnum(), is(AnswerType.SINGLESELECT));
    assertThat(question.getQuestionText(), is(TITLE));
    assertThat(question.getChoices(), new QuestionChoicesMatcher(asList(new QuestionChoiceEntity(choice1.getValue()), new QuestionChoiceEntity(choice2.getValue()))));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test)

Example 17 with QuestionEntity

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

the class QuestionnaireMapperTest method shouldMapMultiSelectQuestionDetailToQuestion.

@Test
public void shouldMapMultiSelectQuestionDetailToQuestion() {
    ChoiceDto choice1 = new ChoiceDto("choice1");
    ChoiceDto choice2 = new ChoiceDto("choice2");
    QuestionDetail questionDefinition = new QuestionDetail(TITLE, QuestionType.MULTI_SELECT);
    questionDefinition.setAnswerChoices(asList(choice1, choice2));
    QuestionEntity question = questionnaireMapper.mapToQuestion(questionDefinition);
    assertThat(question.getAnswerTypeAsEnum(), is(AnswerType.MULTISELECT));
    assertThat(question.getQuestionText(), is(TITLE));
    assertThat(question.getChoices(), new QuestionChoicesMatcher(asList(new QuestionChoiceEntity(choice1.getValue()), new QuestionChoiceEntity(choice2.getValue()))));
    assertThat(question.getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test)

Example 18 with QuestionEntity

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupDefinitionToExistingQuestionGroup.

@Test
public void shouldMapQuestionGroupDefinitionToExistingQuestionGroup() {
    when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
    when(questionDao.getDetails(12)).thenReturn(new QuestionEntity());
    Section section = getSection("S1");
    when(questionGroupDao.getDetails(123)).thenReturn(getQuestionGroup(123, "QG Title", section));
    when(questionGroupDao.retrieveSectionByNameAndQuestionGroupId("S1", 123)).thenReturn(asList(section));
    EventSourceDto eventSourceDto = getEventSource("Create", "Client");
    List<SectionDetail> sectionDetails = asList(getSectionDefinition("S1", 12, TITLE), getSectionDefinition("S2", 0, TITLE));
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(123, TITLE, Arrays.asList(eventSourceDto), sectionDetails, true);
    questionGroupDetail.setActive(false);
    QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(questionGroupDetail);
    assertQuestionGroup(questionGroup, QuestionGroupState.INACTIVE);
    assertThat(questionGroup.isEditable(), is(true));
    verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
    verify(questionDao, times(1)).getDetails(12);
    verify(questionGroupDao, times(1)).getDetails(123);
    verify(questionGroupDao, times(1)).retrieveSectionByNameAndQuestionGroupId("S1", 123);
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Section(org.mifos.platform.questionnaire.domain.Section) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 19 with QuestionEntity

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

the class QuestionnaireMapperTest method shouldMapQuestionDtoToQuestionEntity.

@Test
public void shouldMapQuestionDtoToQuestionEntity() {
    String text = "question";
    String nickname = "nickname";
    QuestionDto questionDto = new QuestionDtoBuilder().withText(text).withNickname(nickname).withMandatory(true).withType(QuestionType.FREETEXT).withOrder(1).build();
    QuestionEntity questionEntity = questionnaireMapper.mapToQuestion(questionDto);
    assertThat(questionEntity.getQuestionText(), is(text));
    assertThat(questionEntity.getNickname(), is(nickname));
    assertThat(questionEntity.getAnswerTypeAsEnum(), is(AnswerType.FREETEXT));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 20 with QuestionEntity

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

the class QuestionnaireMapperTest method shouldMapSmartSelectQuestionDetailToQuestion.

@Test
public void shouldMapSmartSelectQuestionDetailToQuestion() {
    ChoiceDto choice1 = new ChoiceDto("choice1");
    choice1.setTags(asList("Tag1", "Tag2"));
    ChoiceDto choice2 = new ChoiceDto("choice2");
    choice2.setTags(asList("Tag3"));
    QuestionDetail questionDefinition = new QuestionDetail(TITLE, QuestionType.SMART_SELECT);
    questionDefinition.setActive(true);
    questionDefinition.setAnswerChoices(asList(choice1, choice2));
    QuestionEntity question = questionnaireMapper.mapToQuestion(questionDefinition);
    assertThat(question.getAnswerTypeAsEnum(), is(AnswerType.SMARTSELECT));
    assertThat(question.getQuestionText(), is(TITLE));
    assertThat(question.getChoices(), new QuestionChoicesMatcher(asList(getChoiceEntity("choice1", "Tag1", "Tag2"), getChoiceEntity("choice2", "Tag3"))));
    assertThat(question.getQuestionStateAsEnum(), is(QuestionState.ACTIVE));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test)

Aggregations

QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)25 Test (org.junit.Test)16 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)9 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)7 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)7 Transactional (org.springframework.transaction.annotation.Transactional)7 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)5 Section (org.mifos.platform.questionnaire.domain.Section)3 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)3 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)3 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)2 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)1 QuestionType (org.mifos.platform.questionnaire.service.QuestionType)1