Package de.hpi.eworld.db

Examples of de.hpi.eworld.db.DatabaseAccess


   *
   * @author Nico Naumann
   */
  @Before
  public void initDBSettings() {
    DatabaseAccess dba = DatabaseAccess.getInstance();
    backupSettings = dba.readSettings();
    dba.writeSettings(DB_URL, DB_PORT, DB_NAME, DB_USER, DB_PW);
    if(!this.schemaIsOk && !dba.checkSchema()) {
      dba.setSchema();
      this.schemaIsOk = true;
    }
  }
View Full Code Here


   *
   * @author Nico Naumann
   */
  @After
  public void restoreDBSettings() {
    DatabaseAccess dba = DatabaseAccess.getInstance();
    dba.writeSettings(backupSettings.get(DatabaseAccess.KEY_DBURL), Integer
        .valueOf(backupSettings.get(DatabaseAccess.KEY_DBPORT)),
        backupSettings.get(DatabaseAccess.KEY_DBNAME), backupSettings
            .get(DatabaseAccess.KEY_DBUSER), backupSettings
            .get(DatabaseAccess.KEY_DBPW));
  }
View Full Code Here

  @Test
  public void checkDatabaseSettings() {
    if (DATABASE_DISABLED)
      return;
   
    DatabaseAccess dba = DatabaseAccess.getInstance();
    String test_URL = "192.168.3.1";
    int test_Port = 12345;
    String test_Name = "gr17nfe";
    String test_User = "sdvioprev";
    String test_PW = "d83fa;q3fv";

    dba.writeSettings(test_URL, test_Port, test_Name, test_User, test_PW);
    Hashtable<String, String> settings = dba.readSettings();
    Assert.assertEquals(test_URL, settings.get(DatabaseAccess.KEY_DBURL));
    Assert.assertEquals(test_Port, Integer.valueOf(
        settings.get(DatabaseAccess.KEY_DBPORT)).intValue());
    Assert.assertEquals(test_Name, settings.get(DatabaseAccess.KEY_DBNAME));
    Assert.assertEquals(test_User, settings.get(DatabaseAccess.KEY_DBUSER));
View Full Code Here

   */
  @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());
  }
View Full Code Here

  @Test
  public void testDatabaseAccessSave() {
    if (DATABASE_DISABLED)
      return;
   
    DatabaseAccess dba = DatabaseAccess.getInstance();
    dba.checkSettings();
   
    ModelManager mm = ModelManager.getInstance();
    ModelManagerMockUp mmm = ModelManagerMockUp.getInstance();
   
    mm.clearModel();
   
    ArrayList<ModelElement> testCase = TestCaseUtil.createSampleTestcase();
    for(ModelElement m : testCase) {
      mm.addModelElement(m);
      // save test case structural information for later use
      mmm.addModelElement(m);
    }
    // save and load again from the DB
    dba.save();
    dba.load();
   
    Collection<ModelElement> loadedModelElements = mm.getAllModelElements();
    ModelManagerMockUp mmmCompare = ModelManagerMockUp.getInstance();
    for(ModelElement m : loadedModelElements) {
      mmmCompare.addModelElement(m);
View Full Code Here

    Assert.assertEquals(true, found);
  }
 
   
  private Collection<ModelElement> databaseSaveLoadGeneric(ModelElement testElement) {
    DatabaseAccess dba = DatabaseAccess.getInstance();
    dba.checkSettings();
   
    ModelManager mm = ModelManager.getInstance();
    mm.clearModel();
    mm.addModelElement(testElement);
   
    // save and load again from the DB
    dba.save();
    dba.load();
   
    Collection<ModelElement> loadedModelElements = mm.getAllModelElements();
    return loadedModelElements;
  }
View Full Code Here

TOP

Related Classes of de.hpi.eworld.db.DatabaseAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.