Ejemplo n.º 1
0
 public TrustedAuthorityManager(String gtsURI, TrustLevelLookup lookup, DBManager dbManager) {
   log = LogFactory.getLog(this.getClass().getName());
   this.gtsURI = gtsURI;
   this.dbManager = dbManager;
   this.db = dbManager.getDatabase();
   this.lookup = lookup;
 }
Ejemplo n.º 2
0
 protected void tearDown() throws Exception {
   super.tearDown();
   try {
     assertEquals(0, db.getDatabase().getUsedConnectionCount());
     // db.getDatabase().destroyDatabase();
   } catch (Exception e) {
     FaultUtil.printFault(e);
     assertTrue(false);
   }
 }
Ejemplo n.º 3
0
 protected void setUp() throws Exception {
   super.setUp();
   try {
     db = Utils.getDBManager();
     assertEquals(0, db.getDatabase().getUsedConnectionCount());
   } catch (Exception e) {
     FaultUtil.printFault(e);
     assertTrue(false);
   }
 }
Ejemplo n.º 4
0
  public synchronized void buildDatabase() throws GTSInternalFault {
    if (!dbBuilt) {
      try {
        db.createDatabase();
        if (!this.db.tableExists(TrustedAuthorityTable.TABLE_NAME)) {
          String sql = dbManager.getTrustedAuthorityTable().getCreateTableSQL();
          db.update(sql);
        }

        if (!this.db.tableExists(TrustedAuthorityTrustLevelsTable.TABLE_NAME)) {
          String sql = dbManager.getTrustedAuthorityTrustLevelsTable().getCreateTableSQL();
          db.update(sql);
        }
        dbBuilt = true;
      } catch (Exception e) {
        this.log.error("Unexpected error in creating the database.", e);
        GTSInternalFault fault = new GTSInternalFault();
        fault.setFaultString("Unexpected error in creating the database.");
        throw fault;
      }
    }
  }
Ejemplo n.º 5
0
 public void testCreateAndDestroy() {
   GTSAuthorityManager am = new GTSAuthorityManager(GTS_URI, getAuthoritySyncTime(), db);
   try {
     am.clearDatabase();
     assertTrue(db.getDatabase().tableExists(AuthorityTable.TABLE_NAME));
     am.clearDatabase();
   } catch (Exception e) {
     FaultUtil.printFault(e);
     assertTrue(false);
   } finally {
     try {
       am.clearDatabase();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 6
0
  public void testUpdateRollback() {
    GTSAuthorityManager am = new GTSAuthorityManager(GTS_URI, getAuthoritySyncTime(), db);
    int count = 5;
    AuthorityGTS[] a = new AuthorityGTS[count];
    Connection c = null;
    try {
      am.clearDatabase();
      for (int i = 0; i < count; i++) {
        a[i] = getAuthority("GTS " + i, 1);
        assertFalse(am.doesAuthorityExist(a[i].getServiceURI()));
        assertEquals(i, am.getAuthorityCount());
        am.addAuthority(a[i]);
        assertTrue(am.doesAuthorityExist(a[i].getServiceURI()));
        assertEquals((i + 1), am.getAuthorityCount());
        assertEquals(a[i], am.getAuthority(a[i].getServiceURI()));

        for (int j = 0; j < i; j++) {
          a[j].setPriority(a[j].getPriority() + 1);
          assertEquals(a[j], am.getAuthority(a[j].getServiceURI()));
        }
      }
      c = db.getDatabase().getConnection();
      c.setAutoCommit(false);
      for (int i = 0; i < count; i++) {
        a[i].setPriority(a[i].getPriority() + 1);
        am.updateAuthorityPriority(c, a[i].getServiceURI(), a[i].getPriority());
      }

      for (int i = 0; i < count; i++) {
        assertEquals((a[i].getPriority() - 1), am.getAuthority(a[i].getServiceURI()).getPriority());
      }

      c.commit();

      for (int i = 0; i < count; i++) {
        assertEquals(a[i], am.getAuthority(a[i].getServiceURI()));
      }

      for (int i = 0; i < count; i++) {
        a[i].setPriority(a[i].getPriority() + 1);
        am.updateAuthorityPriority(c, a[i].getServiceURI(), a[i].getPriority());
      }

      try {
        PreparedStatement bad = c.prepareStatement("INSERT INTO NOTHING SET VALUES(1,2)");
        bad.executeUpdate();
        try {
          c.commit();
        } catch (Exception com) {
          c.rollback();
        }
      } catch (Exception ex) {
        c.rollback();
      }
      for (int i = 0; i < count; i++) {
        a[i].setPriority(a[i].getPriority() - 1);
        assertEquals(a[i], am.getAuthority(a[i].getServiceURI()));
      }
      c.setAutoCommit(true);
    } catch (Exception e) {
      FaultUtil.printFault(e);
      assertTrue(false);
    } finally {
      if (c != null) {
        try {
          c.setAutoCommit(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
        db.getDatabase().releaseConnection(c);
      }
      try {
        am.clearDatabase();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 7
0
 public PermissionManager(DBManager dbManager) {
   log = LogFactory.getLog(this.getClass().getName());
   this.dbManager = dbManager;
   this.db = dbManager.getDatabase();
 }