Skip to content

Instantly share code, notes, and snippets.

@trishagee
Created December 20, 2013 15:07
Show Gist options
  • Save trishagee/8056046 to your computer and use it in GitHub Desktop.
Save trishagee/8056046 to your computer and use it in GitHub Desktop.
@Test()
public void testSingleServer() {
MongoClientURI u = new MongoClientURI("mongodb://db.example.com");
assertEquals(1, u.getHosts().size());
assertEquals("db.example.com", u.getHosts().get(0));
assertNull(u.getDatabase());
assertNull(u.getCollection());
assertNull( u.getUsername());
assertEquals(null, u.getPassword());
}
@Test()
public void testWithDatabase() {
MongoClientURI u = new MongoClientURI("mongodb://foo/bar");
assertEquals(1, u.getHosts().size());
assertEquals("foo", u.getHosts().get(0));
assertEquals("bar", u.getDatabase());
assertEquals(null, u.getCollection());
assertEquals(null, u.getUsername());
assertEquals(null, u.getPassword());
}
@Test()
public void testWithCollection() {
MongoClientURI u = new MongoClientURI("mongodb://localhost/test.my.coll");
assertEquals("test", u.getDatabase());
assertEquals("my.coll", u.getCollection());
}
@Test()
public void testBasic2() {
MongoClientURI u = new MongoClientURI("mongodb://foo/bar.goo");
assertEquals(1, u.getHosts().size());
assertEquals("foo", u.getHosts().get(0));
assertEquals("bar", u.getDatabase());
assertEquals("goo", u.getCollection());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment