Ejemplo n.º 1
0
  @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);
  }
Ejemplo n.º 2
0
  @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();
  }