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

    Mongo m = new Mongo();

    DB db = m.getDB("admin");

    ListDatabasesCmd cmd = new ListDatabasesCmd();

    db.executeCommand(cmd);
  }
Beispiel #4
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();
  }