Search in sources :

Example 6 with Transactional

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"))));
}
Also used : QuestionChoiceEntity(org.mifos.platform.questionnaire.domain.QuestionChoiceEntity) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionChoicesMatcher(org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Transactional

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));
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Transactional

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());
}
Also used : QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Transactional

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()));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Section(org.mifos.platform.questionnaire.domain.Section) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with Transactional

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()));
}
Also used : QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)4561 Test (org.junit.Test)1387 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)724 DAOException (com.tomasio.projects.trainning.exception.DAOException)385 CoreException (com.tomasio.projects.trainning.exeption.CoreException)372 ArrayList (java.util.ArrayList)324 Date (java.util.Date)252 Query (javax.persistence.Query)218 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)213 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)211 WithMockUser (org.springframework.security.test.context.support.WithMockUser)204 HashMap (java.util.HashMap)187 List (java.util.List)163 User (io.github.jhipster.sample.domain.User)150 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)135 HashSet (java.util.HashSet)135 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)132 UUID (java.util.UUID)131 Rollback (org.springframework.test.annotation.Rollback)109 ParseException (java.text.ParseException)108