@After public void shutdownDatabase() throws Exception { if (Database.isStarted()) { wipeDatabase(); Database.shutdown(); } }
private void wipeDatabase() { DBBroker broker = null; Transaction tx = Database.requireTransaction(); try { broker = db.acquireBroker(); broker.removeCollection(tx.tx, broker.getCollection(XmldbURI.ROOT_COLLECTION_URI)); tx.commit(); } catch (PermissionDeniedException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { tx.abortIfIncomplete(); db.releaseBroker(broker); } }
@Before public void startupDatabase() { ConfigFile configFileAnnotation = getClass().getAnnotation(ConfigFile.class); assert configFileAnnotation != null; Database.ensureStarted(new File(configFileAnnotation.value())); db = new Database(SecurityManager.SYSTEM_USER); wipeDatabase(); ListenerManager.configureTriggerDispatcher(db); // config file gets erased by command above }