Search in sources :

Example 21 with QuestionEntity

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

the class QuestionnaireMapperTest method shouldMapNumericQuestionDetailToQuestion.

@Test
public void shouldMapNumericQuestionDetailToQuestion() {
    QuestionDetail questionDetail = new QuestionDetail(TITLE, QuestionType.NUMERIC);
    questionDetail.setNumericMin(10);
    questionDetail.setNumericMax(100);
    QuestionEntity questionEntity = questionnaireMapper.mapToQuestion(questionDetail);
    assertThat(questionEntity, is(notNullValue()));
    assertThat(questionEntity.getQuestionText(), is(TITLE));
    assertThat(questionEntity.getAnswerTypeAsEnum(), is(AnswerType.NUMBER));
    assertThat(questionEntity.getNumericMin(), is(10));
    assertThat(questionEntity.getNumericMax(), is(100));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 22 with QuestionEntity

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

the class QuestionDaoIntegrationTest method testRetrieveByState.

@Test
@Transactional
public void testRetrieveByState() throws SystemException {
    QuestionDetail questionDetail2 = defineQuestion("Title2" + System.currentTimeMillis(), QuestionType.NUMERIC);
    QuestionDetail questionDetail1 = defineQuestion("Title1" + System.currentTimeMillis(), QuestionType.NUMERIC);
    List<String> expectedTitles = asList(questionDetail1.getText(), questionDetail2.getText());
    List<QuestionEntity> actualQuestions = questionDao.retrieveByState(QuestionState.ACTIVE.getValue());
    assertThat(actualQuestions.size(), is(2));
    assertThat(actualQuestions.get(0).getQuestionText(), is(expectedTitles.get(0)));
    assertThat(actualQuestions.get(1).getQuestionText(), is(expectedTitles.get(1)));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with QuestionEntity

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

the class QuestionDaoIntegrationTest method testRetrieveByStateExcluding.

@Test
@Transactional
public void testRetrieveByStateExcluding() throws SystemException {
    QuestionDetail questionDetail3 = defineQuestion("Title3" + System.currentTimeMillis(), QuestionType.NUMERIC);
    QuestionDetail questionDetail2 = defineQuestion("Title2" + System.currentTimeMillis(), QuestionType.NUMERIC);
    QuestionDetail questionDetail1 = defineQuestion("Title1" + System.currentTimeMillis(), QuestionType.NUMERIC);
    List<String> expectedTitles = asList(questionDetail1.getText(), questionDetail2.getText());
    List<QuestionEntity> actualQuestions = questionDao.retrieveByStateExcluding(asList(questionDetail3.getId()), QuestionState.ACTIVE.getValue());
    assertThat(actualQuestions.size(), is(2));
    assertThat(actualQuestions.get(0).getQuestionText(), is(expectedTitles.get(0)));
    assertThat(actualQuestions.get(1).getQuestionText(), is(expectedTitles.get(1)));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with QuestionEntity

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

the class QuestionnaireServiceIntegrationTest method shouldUpdateQuestion.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldUpdateQuestion() throws SystemException {
    String questionTitle = TITLE + currentTimeMillis();
    QuestionDetail questionDetail = defineQuestion(questionTitle, QuestionType.DATE, true);
    assertNotNull(questionDetail);
    Integer questionId = questionDetail.getId();
    assertNotNull(questionId);
    QuestionEntity questionEntity = questionDao.getDetails(questionId);
    assertNotNull(questionEntity);
    Assert.assertEquals(questionTitle, questionEntity.getQuestionText());
    Assert.assertEquals(AnswerType.DATE, questionEntity.getAnswerTypeAsEnum());
    Assert.assertEquals(questionDetail.getAnswerChoices(), asList());
    questionDetail.setActive(false);
    questionDetail.setText(questionTitle + 1);
    Assert.assertThat(questionDao.retrieveCountOfQuestionsWithText(questionTitle).get(0).intValue(), is(1));
    // See http://forum.springsource.org/showthread.php?t=18951, integration test practice recommended by Rod Johnson
    SessionFactoryUtils.getSession(sessionFactory.getObject(), false).clear();
    questionnaireService.defineQuestion(questionDetail);
    Assert.assertThat(questionDao.retrieveCountOfQuestionsWithText(questionTitle).get(0).intValue(), is(0));
    questionEntity = questionDao.getDetails(questionId);
    assertNotNull(questionEntity);
    Assert.assertEquals(questionTitle + 1, questionEntity.getQuestionText());
    Assert.assertEquals(questionTitle + 1, questionEntity.getQuestionText());
    Assert.assertEquals(AnswerType.DATE, questionEntity.getAnswerTypeAsEnum());
    Assert.assertEquals(questionDetail.getAnswerChoices(), asList());
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with QuestionEntity

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

the class QuestionnaireValidatorImpl method questionHasDuplicateTitle.

private boolean questionHasDuplicateTitle(QuestionDto question, boolean withQuestionTypeCheck) {
    List<QuestionEntity> questions = questionDao.retrieveByText(question.getText());
    boolean result = false;
    if (isNotEmpty(questions)) {
        result = true;
        if (withQuestionTypeCheck) {
            QuestionEntity questionEntity = questions.get(0);
            result = !areSameQuestionTypes(question.getType(), questionEntity.getAnswerTypeAsEnum()) || haveIncompatibleChoices(question, questionEntity);
        }
    }
    return result;
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity)

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