/** * 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()); } }
/** * 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()); } }
@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"); } }
@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"); } }
@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()); }
@BeforeTransaction public void beforeTransaction() { assertInTransaction(false); this.inTransaction = true; BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls++; clearPersonTable(jdbcTemplate); assertEquals("Adding yoda", 1, addPerson(jdbcTemplate, YODA)); }
/** Load information into the database. */ @BeforeTransaction public void prepareDatabase() { synchronized (this) { if (!run) { prepareTestData(getModuleName()); } run = true; } ((ConfigurableApplicationContext) this.applicationContext).registerShutdownHook(); }
@BeforeTransaction public void assertBeforeTransaction() { if (nonNull(beforeTransactionAssertion)) { final RedisConnection connection = connectionFactory.getConnection(); beforeTransactionAssertion.assertBeforeTransaction(connection); connection.close(); } }
@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); }
/** * 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)); }
@BeforeTransaction public void beforeTransaction() { assertInTransaction(false); this.inTransaction = true; BeforeAndAfterTransactionAnnotationTests.numBeforeTransactionCalls++; clearPersonTable(simpleJdbcTemplate); assertEquals("Adding yoda", 1, addPerson(simpleJdbcTemplate, YODA)); }
@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)); }
@BeforeTransaction public void setUp() { try { if (!m_populated) { m_databasePopulator.populateDatabase(); } } catch (Throwable e) { e.printStackTrace(System.err); } finally { m_populated = true; } }
@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; } }
@BeforeTransaction public void setUp() { try { if (!m_populated) { m_populator.populateDatabase(); } } catch (Throwable e) { e.printStackTrace(System.err); } finally { m_populated = true; } }
@BeforeTransaction public void populateDatabase() { try { if (!m_populated) { m_populator.populateDatabase(); } } catch (Throwable e) { e.printStackTrace(System.err); } finally { m_populated = true; } }
/** * @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"); }
@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(); }
/** * 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); } }
/** * 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); } }
/** * 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); } }