Search in sources :

Example 1 with Transactional

use of cn.taketoday.transaction.annotation.Transactional in project today-infrastructure by TAKETODAY.

the class ConcreteTransactionalTestNGContextTests method verifyApplicationContextSet.

@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void verifyApplicationContextSet() {
    TransactionAssert.assertThatTransaction().isNotActive();
    assertThat(super.applicationContext).as("The application context should have been set due to ApplicationContextAware semantics.").isNotNull();
    Employee employeeBean = (Employee) super.applicationContext.getBean("employee");
    assertThat(employeeBean.getName()).as("employee's name.").isEqualTo("John Smith");
}
Also used : Employee(cn.taketoday.beans.testfixture.beans.Employee) Test(org.testng.annotations.Test) Transactional(cn.taketoday.transaction.annotation.Transactional)

Example 2 with Transactional

use of cn.taketoday.transaction.annotation.Transactional in project today-infrastructure by TAKETODAY.

the class InferredDataSourceTransactionalSqlScriptsTests method database2.

@Test
@Transactional("txMgr2")
@Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(transactionManager = "txMgr2"))
void database2() {
    assertThatTransaction().isActive();
    assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert");
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test) Transactional(cn.taketoday.transaction.annotation.Transactional)

Example 3 with Transactional

use of cn.taketoday.transaction.annotation.Transactional in project today-infrastructure by TAKETODAY.

the class InferredDataSourceTransactionalSqlScriptsTests method database1.

@Test
@Transactional("txMgr1")
@Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionManager = "txMgr1"))
void database1() {
    assertThatTransaction().isActive();
    assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert");
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test) Transactional(cn.taketoday.transaction.annotation.Transactional)

Example 4 with Transactional

use of cn.taketoday.transaction.annotation.Transactional in project today-infrastructure by TAKETODAY.

the class HibernateSessionFlushingTests method findSamWithReadOnlySession.

// SPR-16956
@Test
@Transactional(readOnly = true)
public void findSamWithReadOnlySession() {
    Person sam = personService.findByName(SAM);
    sam.setName("Vlad");
    // By setting setDefaultReadOnly(true), the user can no longer modify any entity...
    Session session = sessionFactory.getCurrentSession();
    session.flush();
    session.refresh(sam);
    assertThat(sam.getName()).isEqualTo("Sam");
}
Also used : Person(cn.taketoday.test.context.junit4.orm.domain.Person) Session(org.hibernate.Session) Test(org.junit.Test) Transactional(cn.taketoday.transaction.annotation.Transactional)

Example 5 with Transactional

use of cn.taketoday.transaction.annotation.Transactional in project today-framework by TAKETODAY.

the class InferredDataSourceTransactionalSqlScriptsTests method database1.

@Test
@Transactional("txMgr1")
@Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionManager = "txMgr1"))
void database1() {
    assertThatTransaction().isActive();
    assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert");
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test) Transactional(cn.taketoday.transaction.annotation.Transactional)

Aggregations

Transactional (cn.taketoday.transaction.annotation.Transactional)10 Test (org.junit.jupiter.api.Test)6 JdbcTemplate (cn.taketoday.jdbc.core.JdbcTemplate)4 Employee (cn.taketoday.beans.testfixture.beans.Employee)2 ClassPathResource (cn.taketoday.core.io.ClassPathResource)2 ResourceDatabasePopulator (cn.taketoday.jdbc.datasource.init.ResourceDatabasePopulator)2 Person (cn.taketoday.test.context.junit4.orm.domain.Person)2 Session (org.hibernate.Session)2 Test (org.junit.Test)2 Test (org.testng.annotations.Test)2