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()))));
}
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));
}
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);
}
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));
}
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));
}
Aggregations