Package org.mongodb.morphia.testdaos

Examples of org.mongodb.morphia.testdaos.HotelDAO


        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());
    }
View Full Code Here


        assertEquals(0, hotelDAO.count());
    }

    @Test
    public void testSaveEntityWithId() throws Exception {
        final HotelDAO hotelDAO = new HotelDAO(getMorphia(), getMongoClient());

        final Hotel borg = new Hotel();
        borg.setName("Hotel Borg");
        borg.setStars(4);
        hotelDAO.save(borg);

        final Hotel hotelLoaded = hotelDAO.get(borg.getId());
        hotelLoaded.setStars(5);
        hotelDAO.save(hotelLoaded);
        final Hotel hotelReloaded = hotelDAO.get(borg.getId());
        assertEquals(5, hotelReloaded.getStars());
    }
View Full Code Here

TOP

Related Classes of org.mongodb.morphia.testdaos.HotelDAO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.