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