Beispiel #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);
  }
Beispiel #2
0
  @Test
  public void testDBName() throws Exception {

    Mongo m = new Mongo();

    try {
      new DBImpl(null, null, null);
      fail();
    } catch (Exception e) {
      // ok
    }

    try {
      new DBImpl(m, null, "");
      fail();
    } catch (Exception e) {
      // ok
    }

    try {
      new DBImpl(m, null, "a.b");
      fail();
    } catch (Exception e) {
      // ok
    }

    DBImpl db = new DBImpl(m, m.getConnection(), "test_me");

    assert (db.getName().equals("test_me"));

    db.close();
  }