use of org.springframework.transaction.annotation.Transactional in project head by mifos.
the class QuestionnaireServiceIntegrationTest method shouldDefineMultiSelectQuestion.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldDefineMultiSelectQuestion() throws SystemException {
String questionTitle = TITLE + currentTimeMillis();
QuestionDetail questionDetail = defineQuestion(questionTitle, QuestionType.MULTI_SELECT, asList("choice1", "choice2"));
Assert.assertNotNull(questionDetail);
Integer questionId = questionDetail.getId();
assertNotNull(questionId);
QuestionEntity questionEntity = questionDao.getDetails(questionId);
assertNotNull(questionEntity);
Assert.assertEquals(questionTitle, questionEntity.getQuestionText());
Assert.assertEquals(AnswerType.MULTISELECT, questionEntity.getAnswerTypeAsEnum());
assertThat(questionEntity.getChoices(), new QuestionChoicesMatcher(asList(new QuestionChoiceEntity("choice1"), new QuestionChoiceEntity("choice2"))));
}
use of org.springframework.transaction.annotation.Transactional in project head by mifos.
the class QuestionnaireServiceIntegrationTest method shouldSaveQuestionWithSmartSelectOptionType.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldSaveQuestionWithSmartSelectOptionType() {
String quesTitle = "Ques" + currentTimeMillis();
QuestionEntity questionEntity = new QuestionEntity();
questionEntity.setAnswerType(AnswerType.SMARTSELECT);
questionEntity.setQuestionState(QuestionState.ACTIVE);
questionEntity.setNickname(quesTitle);
questionEntity.setQuestionText(quesTitle);
questionEntity.setChoices(asList(getChoice("Choice1", 0, "Tag1", "Tag2"), getChoice("Choice2", 1, "Tag4")));
Integer quesId = questionDao.create(questionEntity);
QuestionEntity newQuestionEntity = questionDao.getDetails(quesId);
assertThat(newQuestionEntity, is(notNullValue()));
assertThat(newQuestionEntity.getAnswerTypeAsEnum(), is(AnswerType.SMARTSELECT));
assertThat(newQuestionEntity.getChoices(), is(notNullValue()));
assertThat(newQuestionEntity.getChoices().size(), is(2));
assertThat(newQuestionEntity.getChoices().get(0).getChoiceText(), is("Choice1"));
assertThat(newQuestionEntity.getChoices().get(0).getTags(), is(notNullValue()));
assertThat(newQuestionEntity.getChoices().get(0).getTags().size(), is(2));
assertThat(newQuestionEntity.getChoices().get(1).getChoiceText(), is("Choice2"));
assertThat(newQuestionEntity.getChoices().get(1).getTags(), is(notNullValue()));
assertThat(newQuestionEntity.getChoices().get(1).getTags().size(), is(1));
}
use of org.springframework.transaction.annotation.Transactional in project head by mifos.
the class QuestionnaireServiceIntegrationTest method shouldDefineQuestion.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldDefineQuestion() 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());
}
use of org.springframework.transaction.annotation.Transactional 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()));
}
use of org.springframework.transaction.annotation.Transactional in project head by mifos.
the class QuestionGroupInstanceDaoIntegrationTest method shouldGetAllLatestQuestionGroupInstancesByEntityAndEventSourceId.
@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldGetAllLatestQuestionGroupInstancesByEntityAndEventSourceId() {
List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
QuestionGroup questionGroup1 = questionGroupDao.getDetails(defineQuestionGroup("QG2" + currentTimeMillis(), "View", "Client", details, false).getId());
QuestionGroup questionGroup2 = questionGroupDao.getDetails(defineQuestionGroup("QG1" + currentTimeMillis(), "View", "Client", details, false).getId());
QuestionGroup questionGroup3 = questionGroupDao.getDetails(defineQuestionGroup("QG3" + currentTimeMillis(), "View", "Client", details, false).getId());
List<QuestionGroupInstance> questionGroupInstances = asList(getQuestionGroupInstance(2010, 7, 24, questionGroup1, 101, 1), getQuestionGroupInstance(2010, 7, 25, questionGroup1, 101, 2), getQuestionGroupInstance(2010, 7, 24, questionGroup2, 101, 1), getQuestionGroupInstance(2010, 7, 25, questionGroup2, 101, 2), getQuestionGroupInstance(2010, 7, 26, questionGroup2, 101, 3), getQuestionGroupInstance(2010, 7, 24, questionGroup3, 101, 1), getQuestionGroupInstance(2010, 7, 26, questionGroup3, 101, 2));
questionGroupInstanceDao.saveOrUpdateAll(questionGroupInstances);
int eventSourceId = eventSourceDao.retrieveByEventAndSource("View", "Client").get(0).getId();
// questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId)
// is a hack to flush the entities as method under test is in SQL and not HQL
questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId);
List<QuestionGroupInstance> list = questionGroupInstanceDao.retrieveLatestQuestionGroupInstancesByEntityIdAndEventSourceId(101, eventSourceId);
assertThat(list, is(notNullValue()));
assertThat(list.size(), is(3));
assertThat((list.get(0)).getId(), is(questionGroupInstances.get(4).getId()));
assertThat((list.get(1)).getId(), is(questionGroupInstances.get(6).getId()));
assertThat((list.get(2)).getId(), is(questionGroupInstances.get(1).getId()));
}
Aggregations