示例#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;
 }
 protected void tearDown() throws Exception {
   super.tearDown();
   try {
     assertEquals(0, db.getDatabase().getUsedConnectionCount());
     // db.getDatabase().destroyDatabase();
   } catch (Exception e) {
     FaultUtil.printFault(e);
     assertTrue(false);
   }
 }
 protected void setUp() throws Exception {
   super.setUp();
   try {
     db = Utils.getDBManager();
     assertEquals(0, db.getDatabase().getUsedConnectionCount());
   } catch (Exception e) {
     FaultUtil.printFault(e);
     assertTrue(false);
   }
 }
 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();
     }
   }
 }
  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();
      }
    }
  }
示例#6
0
 public PermissionManager(DBManager dbManager) {
   log = LogFactory.getLog(this.getClass().getName());
   this.dbManager = dbManager;
   this.db = dbManager.getDatabase();
 }