final Address address = new Address();
address.setStreet("Posthusstraeti 11");
address.setPostCode("101");
borg.setAddress(address);
final HotelDAO hotelDAO = new HotelDAO(getMorphia(), getMongoClient());
hotelDAO.save(borg);
assertEquals(1, hotelDAO.count());
assertNotNull(borg.getId());
final Hotel hotelLoaded = hotelDAO.get(borg.getId());
assertEquals(borg.getName(), hotelLoaded.getName());
assertEquals(borg.getAddress().getPostCode(), hotelLoaded.getAddress().getPostCode());
final Hotel hotelByValue = hotelDAO.findOne("name", "Hotel Borg");
assertNotNull(hotelByValue);
assertEquals(borg.getStartDate(), hotelByValue.getStartDate());
assertTrue(hotelDAO.exists("stars", 4));
final Hotel hilton = new Hotel();
hilton.setName("Hilton Hotel");
hilton.setStars(4);
hilton.setTakesCreditCards(true);
hilton.setStartDate(new Date());
hilton.setType(Hotel.Type.BUSINESS);
final Address hiltonAddress = new Address();
hiltonAddress.setStreet("Some street 44");
hiltonAddress.setPostCode("101");
hilton.setAddress(hiltonAddress);
hotelDAO.save(hilton);
final List<Hotel> allHotels = hotelDAO.find().asList();
assertEquals(2, allHotels.size());
assertEquals(1, hotelDAO.find(hotelDAO.createQuery().offset(1).limit(10)).asList().size());
assertEquals(1, hotelDAO.find(hotelDAO.createQuery().limit(1)).asList().size());
assertTrue(hotelDAO.exists("type", Hotel.Type.BUSINESS));
assertNotNull(hotelDAO.findOne("type", Hotel.Type.LEISURE));
// try updating
final UpdateOperations<Hotel> mods = hotelDAO.createUpdateOperations().inc("stars", 1);
hotelDAO.update(hotelDAO.createQuery().filter("stars", 4), mods);
assertEquals(2, hotelDAO.count(hotelDAO.createQuery().filter("stars", 5)));
hotelDAO.deleteById(borg.getId());
assertEquals(1, hotelDAO.count());
hotelDAO.getCollection().drop();
assertEquals(0, hotelDAO.count());
}