spring-framework / org.springframework.test.context.transaction / TestContextTransactionUtils

TestContextTransactionUtils

abstract class TestContextTransactionUtils

Utility methods for working with transactions and data access related beans within the Spring TestContext Framework.

Mainly for internal use within the framework.

Author
Sam Brannen

Author
Juergen Hoeller

Since
4.1

Properties

DEFAULT_DATA_SOURCE_NAME

static val DEFAULT_DATA_SOURCE_NAME: String

Default bean name for a DataSource: "dataSource".

DEFAULT_TRANSACTION_MANAGER_NAME

static val DEFAULT_TRANSACTION_MANAGER_NAME: String

Default bean name for a PlatformTransactionManager: "transactionManager".

Functions

createDelegatingTransactionAttribute

open static fun createDelegatingTransactionAttribute(testContext: TestContext, targetAttribute: TransactionAttribute): TransactionAttribute

Create a delegating TransactionAttribute for the supplied target TransactionAttribute and TestContext, using the names of the test class and test method to build the name of the transaction.

retrieveDataSource

open static fun retrieveDataSource(testContext: TestContext, name: String): DataSource

Retrieve the DataSource to use for the supplied TestContext.

The following algorithm is used to retrieve the DataSource from the org.springframework.context.ApplicationContext of the supplied test context:

  1. Look up the DataSource by type and name, if the supplied name is non-empty, throwing a BeansException if the named DataSource does not exist.
  2. Attempt to look up the single DataSource by type.
  3. Attempt to look up the primary DataSource by type.
  4. Attempt to look up the DataSource by type and the default data source name.

retrieveTransactionManager

open static fun retrieveTransactionManager(testContext: TestContext, name: String): PlatformTransactionManager

Retrieve the PlatformTransactionManager to use for the supplied TestContext.

The following algorithm is used to retrieve the transaction manager from the org.springframework.context.ApplicationContext of the supplied test context:

  1. Look up the transaction manager by type and explicit name, if the supplied name is non-empty, throwing a BeansException if the named transaction manager does not exist.
  2. Attempt to look up the single transaction manager by type.
  3. Attempt to look up the primary transaction manager by type.
  4. Attempt to look up the transaction manager via a TransactionManagementConfigurer, if present.
  5. Attempt to look up the transaction manager by type and the default transaction manager.