*/
@Test
public void checkDatabaseConnection() {
if (DATABASE_DISABLED)
return;
DatabaseAccess dba = DatabaseAccess.getInstance();
AnnotationConfiguration config = new AnnotationConfiguration();
config.setProperty("hibernate.connection.url", "jdbc:postgresql://"
+ DB_URL + ":" + DB_PORT + "/" + DB_NAME);
config.setProperty("hibernate.connection.username", DB_USER);
config.setProperty("hibernate.connection.password", DB_PW);
SessionFactory sessionFactory = config.configure("hibernate.cfg.xml")
.buildSessionFactory();
Session s = sessionFactory.getCurrentSession();
Transaction tx = null;
try {
tx = s.beginTransaction();
tx.commit();
} catch (Exception e) {
e.printStackTrace();
if (tx != null)
tx.rollback();
System.out.println("WARN - Failed to initialize database connection for Test. Please " +
"check settings @ test.de.hpi.eworld.db.");
Assert.fail();
}
// if we reach this point in the test, we could successfully establish a connection
// with the given settings manually, so lets try it via DatabaseAccess
Assert.assertEquals(true, dba.checkSettings());
}