@Test public void testStrictCollectionCreation() throws Exception { Mongo m = new Mongo(); DB db = new DBImpl(m, m.getConnection(), "org_mongo_driver_DBTest"); db.setDBOptions(new DBOptions().setStrictCollectionMode(true)); for (String n : db.getCollectionNames()) { db.dropCollection(n); } assert (db.getCollectionNames().size() == 0); try { db.getCollection("woogie"); fail(); } catch (Exception e) { // expect an exception as we're in strict mode } assert (db.getCollectionNames().size() == 0); db.setDBOptions(null); assert (db.getCollection("woogie") != null); assert (db.getCollectionNames().size() == 1); }
@Test public void testGetDatabaseNames() throws Exception { Mongo m = new Mongo(); DB db = m.getDB("admin"); ListDatabasesCmd cmd = new ListDatabasesCmd(); db.executeCommand(cmd); }
@Test public void testCreateDrop() throws Exception { Mongo m = new Mongo(); DB db = m.getDB("org_mongo_driver_DBTest"); for (String n : db.getCollectionNames()) { db.dropCollection(n); } assert (db.getCollectionNames().size() == 0); db.getCollection("a"); assert (db.getCollectionNames().size() == 1); db.getCollection("b"); assert (db.getCollectionNames().size() == 2); db.dropCollection("a"); assert (db.getCollectionNames().size() == 1); db.dropCollection("b"); assert (db.getCollectionNames().size() == 0); db.close(); }