类 TestContextTransactionUtils

java.lang.Object
cn.taketoday.test.context.transaction.TestContextTransactionUtils

public abstract class TestContextTransactionUtils extends Object
Utility methods for working with transactions and data access related beans within the TestContext Framework.

Mainly for internal use within the framework.

从以下版本开始:
4.0
作者:
Sam Brannen, Juergen Hoeller, Harry Yang
  • 字段详细资料

    • DEFAULT_DATA_SOURCE_NAME

      public static final String DEFAULT_DATA_SOURCE_NAME
      Default bean name for a DataSource: "dataSource".
      另请参阅:
    • DEFAULT_TRANSACTION_MANAGER_NAME

      public static final String DEFAULT_TRANSACTION_MANAGER_NAME
      Default bean name for a PlatformTransactionManager: "transactionManager".
      另请参阅:
    • logger

      private static final cn.taketoday.logging.Logger logger
  • 构造器详细资料

    • TestContextTransactionUtils

      public TestContextTransactionUtils()
  • 方法详细资料

    • retrieveDataSource

      @Nullable public static DataSource retrieveDataSource(TestContext testContext, @Nullable String name)
      Retrieve the DataSource to use for the supplied test context.

      The following algorithm is used to retrieve the DataSource from the 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.
      参数:
      testContext - the test context for which the DataSource should be retrieved; never null
      name - the name of the DataSource to retrieve (may be null or empty)
      返回:
      the DataSource to use, or null if not found
      抛出:
      cn.taketoday.beans.BeansException - if an error occurs while retrieving an explicitly named DataSource
    • retrieveTransactionManager

      @Nullable public static cn.taketoday.transaction.PlatformTransactionManager retrieveTransactionManager(TestContext testContext, @Nullable String name)
      Retrieve the transaction manager to use for the supplied test context.

      The following algorithm is used to retrieve the transaction manager from the 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 transaction manager via a TransactionManagementConfigurer, if present.
      3. Attempt to look up the single transaction manager by type.
      4. Attempt to look up the primary transaction manager by type.
      5. Attempt to look up the transaction manager by type and the default transaction manager name.
      参数:
      testContext - the test context for which the transaction manager should be retrieved; never null
      name - the name of the transaction manager to retrieve (may be null or empty)
      返回:
      the transaction manager to use, or null if not found
      抛出:
      cn.taketoday.beans.BeansException - if an error occurs while retrieving an explicitly named transaction manager
      IllegalStateException - if more than one TransactionManagementConfigurer exists in the ApplicationContext
    • logBeansException

      private static void logBeansException(TestContext testContext, cn.taketoday.beans.BeansException ex, Class<?> beanType)
    • createDelegatingTransactionAttribute

      public static cn.taketoday.transaction.interceptor.TransactionAttribute createDelegatingTransactionAttribute(TestContext testContext, cn.taketoday.transaction.interceptor.TransactionAttribute targetAttribute)
      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.
      参数:
      testContext - the TestContext upon which to base the name
      targetAttribute - the TransactionAttribute to delegate to
      返回:
      the delegating TransactionAttribute
    • createDelegatingTransactionAttribute

      public static cn.taketoday.transaction.interceptor.TransactionAttribute createDelegatingTransactionAttribute(TestContext testContext, cn.taketoday.transaction.interceptor.TransactionAttribute targetAttribute, boolean includeMethodName)
      Create a delegating TransactionAttribute for the supplied target TransactionAttribute and TestContext, using the names of the test class and test method (if requested) to build the name of the transaction.
      参数:
      testContext - the TestContext upon which to base the name
      targetAttribute - the TransactionAttribute to delegate to
      includeMethodName - true if the test method's name should be included in the name of the transaction
      返回:
      the delegating TransactionAttribute