@Override protected void configure() { super.configure(); final EmbeddedDB instance = DBTestingHelper.get(); bind(EmbeddedDB.class).toInstance(instance); try { bind(DataSource.class).toInstance(DBTestingHelper.get().getDataSource()); bind(IDBI.class).toInstance(DBTestingHelper.getDBI()); } catch (IOException e) { Assert.fail(e.toString()); } } }
@BeforeSuite(groups = {"slow", "mysql"}) public void beforeSuite() throws Exception { DBTestingHelper.start(); }
public static synchronized void start() throws IOException { final EmbeddedDB instance = get(); instance.initialize(); instance.start(); if (isUsingLocalInstance()) { return;
@BeforeMethod(groups = {"slow", "mysql"}) public void beforeMethod() throws Exception { try { DBTestingHelper.get().cleanupAllTables(); } catch (Exception ignored) { } }
public static synchronized EmbeddedDB get() { if (instance == null) { if ("true".equals(System.getProperty("com.ning.billing.dbi.test.h2"))) { log.info("Using h2 as the embedded database"); instance = new H2EmbeddedDB(); } else { if (isUsingLocalInstance()) { log.info("Using MySQL local database"); final String databaseName = System.getProperty("com.ning.billing.dbi.test.localDb.database", "killbill"); final String username = System.getProperty("com.ning.billing.dbi.test.localDb.password", "root"); final String password = System.getProperty("com.ning.billing.dbi.test.localDb.username", "root"); instance = new MySQLStandaloneDB(databaseName, username, password); } else { log.info("Using MySQL as the embedded database"); instance = new MySQLEmbeddedDB(); } } } return instance; }
@BeforeMethod(groups = {"slow", "mysql"}) public void cleanupTablesBetweenMethods() { try { DBTestingHelper.get().cleanupAllTables(); } catch (Exception ignored) { } }
@AfterSuite(groups = {"slow", "mysql"}) public void shutdownMysqlAfterTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException { if (hasFailed()) { log.error("**********************************************************************************************"); log.error("*** TESTS HAVE FAILED - LEAVING DB RUNNING FOR DEBUGGING - MAKE SURE TO KILL IT ONCE DONE ****"); log.error(DBTestingHelper.get().getCmdLineConnectionString()); log.error("**********************************************************************************************"); return; } try { DBTestingHelper.get().stop(); } catch (Exception ignored) { } } }
@BeforeSuite(groups = {"slow", "mysql"}) public void startMysqlBeforeTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException { DBTestingHelper.start(); }
@AfterSuite(groups = {"slow", "mysql"}) public void afterSuite() throws Exception { if (hasFailed()) { log.error("**********************************************************************************************"); log.error("*** TESTS HAVE FAILED - LEAVING DB RUNNING FOR DEBUGGING - MAKE SURE TO KILL IT ONCE DONE ****"); log.error(DBTestingHelper.get().getCmdLineConnectionString()); log.error("**********************************************************************************************"); return; } try { DBTestingHelper.get().stop(); } catch (Exception ignored) { } } }
public static synchronized IDBI getDBI() throws IOException { return new DBIProvider(get().getDataSource()).get(); }