Fixing some errors found when running tests

Most problems fixed manifest depending on the order the tests are executed. This should improve first-run experience for developers.

I ran the tests using:

java version "1.7.0_21"
OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-1ubuntu1)

and  PostgreSQL 9.1.9.