Search in sources :

Example 11 with Transactional

use of org.springframework.transaction.annotation.Transactional in project head by mifos.

the class QuestionGroupInstanceDaoIntegrationTest method shouldPersistQuestionGroupInstance.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldPersistQuestionGroupInstance() throws SystemException {
    String title = "QG1" + currentTimeMillis();
    List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
    QuestionGroupInstance questionGroupInstance = getQuestionGroupInstance(1, questionGroup, 101, "Foo Bar1", "Foo Bar2");
    questionGroupInstanceDao.saveOrUpdateAll(asList(questionGroupInstance));
    QuestionGroupInstance groupInstance = questionGroupInstanceDao.getDetails(questionGroupInstance.getId());
    assertThat(groupInstance, is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().size(), is(2));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getSectionQuestion(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getSectionQuestion(), is(questionGroup.getSections().get(0).getQuestions().get(0)));
    assertThat(groupInstance.getQuestionGroupResponses().get(0).getResponse(), is("Foo Bar1"));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getSectionQuestion(), is(notNullValue()));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getSectionQuestion(), is(questionGroup.getSections().get(1).getQuestions().get(0)));
    assertThat(groupInstance.getQuestionGroupResponses().get(1).getResponse(), is("Foo Bar2"));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) 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)

Example 12 with Transactional

use of org.springframework.transaction.annotation.Transactional in project head by mifos.

the class QuestionGroupInstanceDaoIntegrationTest method shouldGetLatestQuestionGroupInstancesBasedOnQuestionGroupAndEntity.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldGetLatestQuestionGroupInstancesBasedOnQuestionGroupAndEntity() {
    String title = "QG1" + currentTimeMillis();
    List<SectionDetail> details = asList(getSection("S1"), getSection("S2"));
    QuestionGroupDetail questionGroupDetail = defineQuestionGroup(title, "Create", "Client", details, false);
    QuestionGroup questionGroup = questionGroupDao.getDetails(questionGroupDetail.getId());
    QuestionGroupInstance instance1 = getQuestionGroupInstance(1, questionGroup, 101, "Foo Bar1", "Foo Bar2");
    QuestionGroupInstance instance2 = getQuestionGroupInstance(2, questionGroup, 101, "Hello World1", "Hello World2");
    questionGroupInstanceDao.saveOrUpdateAll(asList(instance1, instance2));
    List<QuestionGroupInstance> instances = questionGroupInstanceDao.retrieveLatestQuestionGroupInstanceByQuestionGroupAndEntity(101, questionGroupDetail.getId());
    assertThat(instances, is(notNullValue()));
    assertThat(instances.size(), is(1));
    QuestionGroupInstance qGInst = instances.get(0);
    assertThat(qGInst.getVersionNum(), is(2));
    assertThat(qGInst.getEntityId(), is(101));
    assertThat(qGInst.getQuestionGroup().getId(), is(questionGroupDetail.getId()));
    List<QuestionGroupResponse> qGResponses = qGInst.getQuestionGroupResponses();
    assertThat(qGResponses, is(notNullValue()));
    assertThat(qGResponses.size(), is(2));
    assertThat(qGResponses.get(0).getResponse(), is("Hello World1"));
    assertThat(qGResponses.get(1).getResponse(), is("Hello World2"));
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) 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)

Example 13 with Transactional

use of org.springframework.transaction.annotation.Transactional in project head by mifos.

the class QuestionnaireValidatorIntegrationTest method shouldCheckForInValidEventSource.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldCheckForInValidEventSource() {
    EventSourceDto eventSourceDto = new EventSourceDto("Disburse", "Client", "Disburse Client");
    try {
        questionnaireValidator.validateForEventSource(eventSourceDto);
        fail("Should have raised a validation error for invalid event");
    } catch (SystemException e) {
        assertThat(e.getKey(), is(QuestionnaireConstants.INVALID_EVENT_SOURCE));
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with Transactional

use of org.springframework.transaction.annotation.Transactional in project head by mifos.

the class QuestionnaireValidatorIntegrationTest method shouldCheckForValidEventSource.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldCheckForValidEventSource() {
    EventSourceDto eventSourceDto = new EventSourceDto("Create", "Client", "Create Client");
    try {
        questionnaireValidator.validateForEventSource(eventSourceDto);
        eventSourceDto = new EventSourceDto("View", "Client", "View Client");
        questionnaireValidator.validateForEventSource(eventSourceDto);
        eventSourceDto = new EventSourceDto("Create", "Loan", "Create Loan");
        questionnaireValidator.validateForEventSource(eventSourceDto);
    } catch (SystemException e) {
        fail("Should not have raised a validation error for this event");
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapterFullIT method testAddNodeDirectly.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
@Transactional
public void testAddNodeDirectly() throws InterruptedException {
    OnmsNode node = m_nodeDao.get(NODE_ID);
    assertNotNull(node);
    int firstNodeId = node.getId();
    m_adapter.doAddNode(firstNodeId);
    node = m_nodeDao.get(firstNodeId);
    assertNotNull(node);
    assertNotNull("AssetRecord comment is null", node.getAssetRecord().getComment());
    assertEquals(EXPECTED_COMMENT_FIELD, node.getAssetRecord().getComment());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) 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