Java 类org.springframework.test.context.transaction.BeforeTransaction 实例源码

项目:metaworks_framework    文件:MergeTransactionalTestExecutionListener.java   
/**
 * Run all {@link BeforeTransaction @BeforeTransaction methods} for the
 * specified {@link TestContext test context}. If one of the methods fails,
 * however, the caught exception will be rethrown in a wrapped
 * {@link RuntimeException}, and the remaining methods will <strong>not</strong>
 * be given a chance to execute.
 * @param testContext the current test context
 */
protected void runBeforeTransactionMethods(TestContext testContext) throws Exception {
    try {
        List<Method> methods = getAnnotatedMethods(testContext.getTestClass(), BeforeTransaction.class);
        Collections.reverse(methods);
        for (Method method : methods) {
            if (logger.isDebugEnabled()) {
                logger.debug("Executing @BeforeTransaction method [" + method + "] for test context ["
                        + testContext + "]");
            }
            method.invoke(testContext.getTestInstance());
        }
    }
    catch (InvocationTargetException ex) {
        logger.error("Exception encountered while executing @BeforeTransaction methods for test context ["
                + testContext + "]", ex.getTargetException());
        ReflectionUtils.rethrowException(ex.getTargetException());
    }
}
项目:SparkCommerce    文件:MergeTransactionalTestExecutionListener.java   
/**
 * Run all {@link BeforeTransaction @BeforeTransaction methods} for the
 * specified {@link TestContext test context}. If one of the methods fails,
 * however, the caught exception will be rethrown in a wrapped
 * {@link RuntimeException}, and the remaining methods will <strong>not</strong>
 * be given a chance to execute.
 * @param testContext the current test context
 */
protected void runBeforeTransactionMethods(TestContext testContext) throws Exception {
    try {
        List<Method> methods = getAnnotatedMethods(testContext.getTestClass(), BeforeTransaction.class);
        Collections.reverse(methods);
        for (Method method : methods) {
            if (logger.isDebugEnabled()) {
                logger.debug("Executing @BeforeTransaction method [" + method + "] for test context ["
                        + testContext + "]");
            }
            method.invoke(testContext.getTestInstance());
        }
    }
    catch (InvocationTargetException ex) {
        logger.error("Exception encountered while executing @BeforeTransaction methods for test context ["
                + testContext + "]", ex.getTargetException());
        ReflectionUtils.rethrowException(ex.getTargetException());
    }
}
项目:blcdemo    文件:MergeTransactionalTestExecutionListener.java   
/**
 * Run all {@link BeforeTransaction @BeforeTransaction methods} for the
 * specified {@link TestContext test context}. If one of the methods fails,
 * however, the caught exception will be rethrown in a wrapped
 * {@link RuntimeException}, and the remaining methods will <strong>not</strong>
 * be given a chance to execute.
 * @param testContext the current test context
 */
protected void runBeforeTransactionMethods(TestContext testContext) throws Exception {
    try {
        List<Method> methods = getAnnotatedMethods(testContext.getTestClass(), BeforeTransaction.class);
        Collections.reverse(methods);
        for (Method method : methods) {
            if (logger.isDebugEnabled()) {
                logger.debug("Executing @BeforeTransaction method [" + method + "] for test context ["
                        + testContext + "]");
            }
            method.invoke(testContext.getTestInstance());
        }
    }
    catch (InvocationTargetException ex) {
        logger.error("Exception encountered while executing @BeforeTransaction methods for test context ["
                + testContext + "]", ex.getTargetException());
        ReflectionUtils.rethrowException(ex.getTargetException());
    }
}
项目:karaku    文件:TransactionalTestCucumberExecutionListener.java   
/**
 * Run all {@link BeforeTransaction &#064;BeforeTransaction methods} for the
 * specified {@link TestContext test context}. If one of the methods fails,
 * however, the caught exception will be rethrown in a wrapped
 * {@link RuntimeException}, and the remaining methods will
 * <strong>not</strong> be given a chance to execute.
 * 
 * @param testContext
 *            the current test context
 */
protected void runBeforeTransactionMethods(TestContext testContext)
        throws Exception {

    try {
        List<Method> methods = getAnnotatedMethods(
                testContext.getTestClass(), BeforeTransaction.class);
        Collections.reverse(methods);
        for (Method method : methods) {
            if (logger.isDebugEnabled()) {
                logger.debug("Executing @BeforeTransaction method ["
                        + method + "] for test context [" + testContext
                        + "]");
            }
            method.invoke(testContext.getTestInstance());
        }
    } catch (InvocationTargetException ex) {
        logger.error(
                "Exception encountered while executing @BeforeTransaction methods for test context ["
                        + testContext + "]", ex.getTargetException());
        ReflectionUtils.rethrowException(ex.getTargetException());
    }
}
项目:rjb-blog-multitenancy    文件:AbstractTest.java   
@BeforeTransaction
public void beforeTransaction() {
    if (testName.getMethodName().contains("tenant_2")) {
        this.tenantResolver.setTenantId("rjb-blog-mutlitenancy-2");
    } else if (testName.getMethodName().contains("tenant_3")) {
        this.tenantResolver.setTenantId("rjb-blog-mutlitenancy-3");
    } else if (testName.getMethodName().contains("tenant_4")) {
        this.tenantResolver.setTenantId("rjb-blog-mutlitenancy-4");
    } else {
        // default to tenant 1
        // so all tests in the ProductDaoTest base class will still pass
        this.tenantResolver.setTenantId("rjb-blog-mutlitenancy-1");
    }
}
项目:rjb-blog-multitenancy    文件:AbstractTest.java   
@BeforeTransaction
public void beforeTransaction() {
    if (testName.getMethodName().contains("tenant_2")) {
        this.tenantResolver.setTenantId("rjb-blog-mutlitenancy-2");
    } else {
        // default to tenant 1
        // so all tests in the ProductDaoTest base class will still pass
        this.tenantResolver.setTenantId("rjb-blog-mutlitenancy-1");
    }
}
项目:apollo-custom    文件:AdminServiceTransactionTest.java   
@BeforeTransaction
public void verifyInitialDatabaseState() {
  for (App app : appRepository.findAll()) {
    System.out.println(app.getAppId());
  }
  Assert.assertEquals(0, appRepository.count());
  Assert.assertEquals(7, appNamespaceRepository.count());
  Assert.assertEquals(0, namespaceRepository.count());
  Assert.assertEquals(0, clusterRepository.count());
}
项目:apollo    文件:AdminServiceTransactionTest.java   
@BeforeTransaction
public void verifyInitialDatabaseState() {
  for (App app : appRepository.findAll()) {
    System.out.println(app.getAppId());
  }
  Assert.assertEquals(0, appRepository.count());
  Assert.assertEquals(7, appNamespaceRepository.count());
  Assert.assertEquals(0, namespaceRepository.count());
  Assert.assertEquals(0, clusterRepository.count());
}
项目:spring4-understanding    文件:BeforeAndAfterTransactionAnnotationTests.java   
@BeforeTransaction
public void beforeTransaction() {
    assertInTransaction(false);
    this.inTransaction = true;
    BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls++;
    clearPersonTable(jdbcTemplate);
    assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA));
}
项目:ephesoft    文件:DcmaTestCase.java   
/** Load information into the database. */
@BeforeTransaction
public void prepareDatabase() {
    synchronized (this) {
        if (!run) {
            prepareTestData(getModuleName());
        }
        run = true;
    }
    ((ConfigurableApplicationContext) this.applicationContext).registerShutdownHook();
}
项目:spring-boot-email-tools    文件:BaseRedisTest.java   
@BeforeTransaction
public void assertBeforeTransaction() {
    if (nonNull(beforeTransactionAssertion)) {
        final RedisConnection connection = connectionFactory.getConnection();
        beforeTransactionAssertion.assertBeforeTransaction(connection);
        connection.close();
    }
}
项目:sakai    文件:MessageBundleTest.java   
@BeforeTransaction
public void beforeTransaction()  {
    localeEn = new Locale("en");
    localeFr = new Locale("fr");

    baseName = "basename";
    moduleName = "modulename";

    Assert.notNull(messageBundleService);
    resourceBundleEN = ResourceBundle.getBundle("org/sakaiproject/messagebundle/impl/test/bundle", localeEn);
    resourceBundleFr = ResourceBundle.getBundle("org/sakaiproject/messagebundle/impl/test/bundle", localeFr);

    messageBundleService.saveOrUpdate(baseName, moduleName, resourceBundleEN, localeEn);
    messageBundleService.saveOrUpdate(baseName, moduleName, resourceBundleFr, localeFr);
}
项目:cosmo    文件:AbstractHibernateDaoTestCase.java   
/**
 * SetsUp before transaction.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@BeforeTransaction
public void onSetUpBeforeTransaction() throws Exception {
    // Unbind session from TransactionManager
    session = sessionFactory.openSession();
    TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
}
项目:class-guard    文件:BeforeAndAfterTransactionAnnotationTests.java   
@BeforeTransaction
public void beforeTransaction() {
    assertInTransaction(false);
    this.inTransaction = true;
    BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls++;
    clearPersonTable(simpleJdbcTemplate);
    assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA));
}
项目:class-guard    文件:ConcreteTransactionalJUnit38SpringContextTests.java   
@BeforeTransaction
public void beforeTransaction() {
    this.inTransaction = true;
    assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,
        countRowsInPersonTable(super.simpleJdbcTemplate));
    assertEquals("Adding yoda", 1, addPerson(super.simpleJdbcTemplate, YODA));
}
项目:sakai    文件:MessageBundleTest.java   
@BeforeTransaction
public void beforeTransaction()  {
    localeEn = new Locale("en");
    localeFr = new Locale("fr");

    baseName = "basename";
    moduleName = "modulename";

    Assert.notNull(messageBundleService);
    resourceBundleEN = ResourceBundle.getBundle("org/sakaiproject/messagebundle/impl/test/bundle", localeEn);
    resourceBundleFr = ResourceBundle.getBundle("org/sakaiproject/messagebundle/impl/test/bundle", localeFr);

    messageBundleService.saveOrUpdate(baseName, moduleName, resourceBundleEN, localeEn);
    messageBundleService.saveOrUpdate(baseName, moduleName, resourceBundleFr, localeFr);
}
项目:opennmszh    文件:CriteriaTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:AlarmDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:MemoDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:NodeDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_populator.populateDatabase();
            m_lastPopulator = m_populator;
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:AcknowledgmentDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:AuthorizationTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_populator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:OnmsMapElementDaoHibernateTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:OnmsMapDaoHibernateTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:AssetRecordDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:opennmszh    文件:AckdTest.java   
@BeforeTransaction
public void populateDatabase() {
    try {
        if (!m_populated) {
            m_populator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:jee-exercises    文件:OutOfContainerIntegrationTest.java   
/**
 * @throws Exception e
 */
@BeforeTransaction
public final void outOfContainerIntegrationTestSetUp() throws Exception {
    LOG.trace("Entering outOfContainerIntegrationTestSetUp");
    dbunitConnection = dbUnitHelper.createConnection(dataSource);
    dbUnitHelper.purgeRecycleBin(dbunitConnection);
    DatabaseConfig config = dbunitConnection.getConfig();
    config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new OracleDataTypeFactory());
    LOG.trace("Exiting outOfContainerIntegrationTestSetUp");
}
项目:lazyloris    文件:TestInheritance.java   
@BeforeTransaction
public void prepare() {
    Product p1 = new ProductEntity();
    p1.setName("p1");
    p1.setPrice(1.0);
    p1.setQuantity(1);
    //
    Software p2 = new SoftwareEntity();
    p2.setName("p2");
    p2.setPrice(2.0);
    p2.setQuantity(2);
    p2.setOs("Windows");
    p2.setVendor("MS");
    //
    Book p3 = new BookEntity();
    p3.setName("p3");
    p3.setPrice(3.0);
    p3.setQuantity(3);
    p3.setAuthor("Gavin King");
    p3.setDescription("Hibernate In Action");
    //
    WebBrowser p4 = new WebBrowserEntity();
    p4.setName("p4");
    p4.setPrice(4.0);
    p4.setQuantity(4);
    p4.setOs("Linux");
    p4.setVendor("Apache");
    p4.setHtml5Supported(true);
    //
    EntityManager em = entityManagerFactory.createEntityManager();
    em.getTransaction().begin();
    em.persist(p1);
    em.persist(p2);
    em.persist(p3);
    em.persist(p4);
    em.getTransaction().commit();
    em.close();
}
项目:fuwesta    文件:PostDaoTest.java   
/**
 * Inserting Testdata.
 *
 * @throws Exception if something fails.
 */
@BeforeTransaction
public void setupData() throws Exception {
    if (!deleted
            && (countRowsInTable(POST_TABLE_NAME) > 0 || countRowsInTable("T_USER") > 0)) {
        deleteFromTables("TAG_POSTINGS", "TAG", "POST", "T_USER");
        deleted = true;
    }
    if (countRowsInTable(POST_TABLE_NAME) == 0) {
        setSqlScriptEncoding("UTF-8");
        executeSqlScript("classpath:post-data.sql", false);

    }
}
项目:fuwesta    文件:UserDaoTest.java   
/**
 * Inserting Testdata.
 *
 * @throws Exception if something fails.
 */
@BeforeTransaction
public void setupData() throws Exception {
    if (!deleted && countRowsInTable(USER_TABLE_NAME) > 0) {
        deleteFromTables("TAG_POSTINGS", "TAG", "POST", USER_TABLE_NAME);
        deleted = true;
    }
    if (countRowsInTable(USER_TABLE_NAME) == 0) {
        setSqlScriptEncoding("UTF-8");
        executeSqlScript("classpath:user-data.sql", false);

    }
}
项目:fuwesta    文件:UserServiceImplTransactionalTest.java   
/**
 * Inserting Testdata.
 *
 * @throws Exception if something fails.
 */
@BeforeTransaction
public void setupData() throws Exception {
    if (countRowsInTable(USER_TABLE_NAME) != NUMBER_OF_USERS) {
        deleteFromTables("TAG_POSTINGS", "TAG", "POST", "T_USER");
        executeSqlScript("classpath:user-data.sql", false);

    }
}
项目:OpenNMS    文件:CriteriaTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:OpenNMS    文件:AlarmDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:OpenNMS    文件:MemoDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:OpenNMS    文件:NodeDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_populator.populateDatabase();
            m_lastPopulator = m_populator;
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:OpenNMS    文件:AcknowledgmentDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:OpenNMS    文件:AuthorizationTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_populator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:OpenNMS    文件:OnmsMapElementDaoHibernateTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:OpenNMS    文件:OnmsMapDaoHibernateTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}
项目:OpenNMS    文件:AssetRecordDaoTest.java   
@BeforeTransaction
public void setUp() {
    try {
        if (!m_populated) {
            m_databasePopulator.populateDatabase();
        }
    } catch (Throwable e) {
        e.printStackTrace(System.err);
    } finally {
        m_populated = true;
    }
}