Example usage for org.springframework.core.annotation AnnotationUtils getDefaultValue

List of usage examples for org.springframework.core.annotation AnnotationUtils getDefaultValue

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotationUtils getDefaultValue.

Prototype

@Nullable
public static Object getDefaultValue(@Nullable Class<? extends Annotation> annotationType,
        @Nullable String attributeName) 

Source Link

Document

Retrieve the default value of a named attribute, given the Class annotation type .

Usage

From source file:com.github.springtestdbunit.SingleTransactionTestExecutionListener.java

/**
 * Retrieves the {@link TransactionConfigurationAttributes} for the
 * specified {@link Class class} which may optionally declare or inherit a
 * {@link TransactionConfiguration @TransactionConfiguration}. If a
 * {@link TransactionConfiguration} annotation is not present for the
 * supplied class, the <em>default values</em> for attributes defined in
 * {@link TransactionConfiguration} will be used instead.
 * @param clazz the Class object corresponding to the test class for which
 * the configuration attributes should be retrieved
 * @return a new TransactionConfigurationAttributes instance
 *//*  w ww.  j  a v a  2 s  .c  o  m*/
private TransactionConfigurationAttributes retrieveConfigurationAttributes(TestContext testContext) {
    if (this.configurationAttributes == null) {
        Class<?> clazz = testContext.getTestClass();
        Class<TransactionConfiguration> annotationType = TransactionConfiguration.class;
        TransactionConfiguration config = clazz.getAnnotation(annotationType);
        if (logger.isDebugEnabled()) {
            logger.debug("Retrieved @TransactionConfiguration [" + config + "] for test class [" + clazz + "]");
        }

        String transactionManagerName;
        boolean defaultRollback;
        if (config != null) {
            transactionManagerName = config.transactionManager();
            defaultRollback = config.defaultRollback();
        } else {
            transactionManagerName = (String) AnnotationUtils.getDefaultValue(annotationType,
                    "transactionManager");
            defaultRollback = (Boolean) AnnotationUtils.getDefaultValue(annotationType, "defaultRollback");
        }

        TransactionConfigurationAttributes configAttributes = new TransactionConfigurationAttributes(
                transactionManagerName, defaultRollback);
        if (logger.isDebugEnabled()) {
            logger.debug("Retrieved TransactionConfigurationAttributes [" + configAttributes + "] for class ["
                    + clazz + "]");
        }
        this.configurationAttributes = configAttributes;
    }
    return this.configurationAttributes;
}

From source file:py.una.pol.karaku.test.cucumber.TransactionalTestCucumberExecutionListener.java

/**
 * Retrieves the {@link TransactionConfigurationAttributes} for the
 * specified {@link Class class} which may optionally declare or inherit a
 * {@link TransactionConfiguration &#064;TransactionConfiguration}. If a
 * {@link TransactionConfiguration} annotation is not present for the
 * supplied class, the <em>default values</em> for attributes defined in
 * {@link TransactionConfiguration} will be used instead.
 * // w w w . jav  a 2s  . c  o m
 * @param clazz
 *            the Class object corresponding to the test class for which the
 *            configuration attributes should be retrieved
 * @return a new TransactionConfigurationAttributes instance
 */
private TransactionConfigurationAttributes retrieveConfigurationAttributes(TestContext testContext) {

    if (this.configurationAttributes == null) {
        Class<?> clazz = testContext.getTestClass();
        Class<TransactionConfiguration> annotationType = TransactionConfiguration.class;
        TransactionConfiguration config = clazz.getAnnotation(annotationType);
        if (logger.isDebugEnabled()) {
            logger.debug("Retrieved @TransactionConfiguration [" + config + "] for test class [" + clazz + "]");
        }

        String transactionManagerName;
        boolean defaultRollback;
        if (config != null) {
            transactionManagerName = config.transactionManager();
            defaultRollback = config.defaultRollback();
        } else {
            transactionManagerName = (String) AnnotationUtils.getDefaultValue(annotationType,
                    "transactionManager");
            defaultRollback = (Boolean) AnnotationUtils.getDefaultValue(annotationType, "defaultRollback");
        }

        TransactionConfigurationAttributes configAttributes = new TransactionConfigurationAttributes(
                transactionManagerName, defaultRollback);
        if (logger.isDebugEnabled()) {
            logger.debug("Retrieved TransactionConfigurationAttributes [" + configAttributes + "] for class ["
                    + clazz + "]");
        }
        this.configurationAttributes = configAttributes;
    }
    return this.configurationAttributes;
}

From source file:org.broadleafcommerce.test.MergeTransactionalTestExecutionListener.java

/**
 * <p>/*from  w w  w .  j a  v  a2s  .co m*/
 * Retrieves the {@link TransactionConfigurationAttributes} for the
 * specified {@link Class class} which may optionally declare or inherit a
 * {@link TransactionConfiguration @TransactionConfiguration}. If a
 * {@link TransactionConfiguration} annotation is not present for the
 * supplied class, the <entityManager>default values</entityManager> for attributes defined in
 * {@link TransactionConfiguration} will be used instead.
 * @param clazz the Class object corresponding to the test class for which
 * the configuration attributes should be retrieved
 * @return a new TransactionConfigurationAttributes instance
 */
private TransactionConfigurationAttributes retrieveTransactionConfigurationAttributes(Class<?> clazz) {
    Class<TransactionConfiguration> annotationType = TransactionConfiguration.class;
    TransactionConfiguration config = clazz.getAnnotation(annotationType);
    if (logger.isDebugEnabled()) {
        logger.debug("Retrieved @TransactionConfiguration [" + config + "] for test class [" + clazz + "]");
    }

    String transactionManagerName;
    boolean defaultRollback;
    if (config != null) {
        transactionManagerName = config.transactionManager();
        defaultRollback = config.defaultRollback();
    } else {
        transactionManagerName = (String) AnnotationUtils.getDefaultValue(annotationType, "transactionManager");
        defaultRollback = (Boolean) AnnotationUtils.getDefaultValue(annotationType, "defaultRollback");
    }

    TransactionConfigurationAttributes configAttributes = new TransactionConfigurationAttributes(
            transactionManagerName, defaultRollback);
    if (logger.isDebugEnabled()) {
        logger.debug("Retrieved TransactionConfigurationAttributes [" + configAttributes + "] for class ["
                + clazz + "]");
    }
    return configAttributes;
}