Package org.jongo.model

Examples of org.jongo.model.Friend


    }

    @Test
    public void canInsertPojos() throws Exception {

        Friend friend = new Friend("John");
        Friend friend2 = new Friend("Robert");

        collection.insert(friend, friend2);

        assertThat(collection.count("{name:'John'}")).isEqualTo(1);
        assertThat(collection.count("{name:'Robert'}")).isEqualTo(1);
View Full Code Here


    @Test
    public void canInsertAPojoWithNewObjectId() throws Exception {

        ObjectId id = ObjectId.get();

        collection.withWriteConcern(WriteConcern.SAFE).insert(new Friend(id, "John"));

        assertThat(collection.count("{name : 'John'}")).isEqualTo(1);
        assertThat(id.isNew()).isFalse();
    }
View Full Code Here

    public void canInsertAPojoWithNotNewObjectId() throws Exception {

        ObjectId id = ObjectId.get();
        id.notNew();

        collection.withWriteConcern(WriteConcern.SAFE).insert(new Friend(id, "John"));

        Friend result = collection.findOne(id).as(Friend.class);
        assertThat(result.getId()).isEqualTo(id);
    }
View Full Code Here

    public void canOnlyInsertOnceAPojoWithObjectId() throws Exception {

        ObjectId id = ObjectId.get();
        id.notNew();

        collection.withWriteConcern(WriteConcern.SAFE).insert(new Friend(id, "John"));

        try {
            collection.withWriteConcern(WriteConcern.SAFE).insert(new Friend(id, "John"));
            Assert.fail();
        } catch (MongoException.DuplicateKey e) {
        }
    }
View Full Code Here

        for (int i = 0; i < reps; i++) {
            DBCursor cursor = dbCollection.find().limit(size);
            for (DBObject dbo : cursor) {
                DBObject coord = (DBObject) dbo.get("coordinate");
                Coordinate coordinate = new Coordinate((Integer) coord.get("lat"), (Integer) coord.get("lng"));
                Friend f = new Friend((String) dbo.get("name"), (String) dbo.get("address"), coordinate);
                insertions++;
            }
        }
        return insertions;
    }
View Full Code Here

    public void tearDown() throws Exception {
        dropCollection("friends");
    }

    public Friend newFriend() {
        return new Friend("John", "22 Wall Street Avenue");
    }
View Full Code Here

    }

    @Test
    public void canSort() throws Exception {
        /* given */
        collection.save(new Friend("John", "23 Wall Street Av."));
        collection.save(new Friend("John", "21 Wall Street Av."));
        collection.save(new Friend("John", "22 Wall Street Av."));

        /* when */
        Iterator<Friend> results = collection.find("{}").sort("{'address':1}").as(Friend.class);

        /* then */
 
View Full Code Here

    }

    @Test
    public void createIndexWithUniqueAsOption() {
        collection.ensureIndex("{name: 1}", "{unique: true}");
        collection.save(new Friend("John"));

        try {
            collection.save(new Friend("John"));
            Assert.fail();
        } catch (DuplicateKey e) {
        }
    }
View Full Code Here

    }

    @Test
    public void canCreateGeospacialIndex() throws Exception {
        /* given */
        collection.save(new Friend("John", new Coordinate(1, 1)));
        collection.save(new Friend("Peter", new Coordinate(4, 4)));

        collection.ensureIndex("{ 'coordinate' : '2d'}");

        /* then */
        assertThat(collection.find("{'coordinate': {'$near': [0,0], $maxDistance: 5}}").as(Friend.class).iterator()).hasSize(1);
View Full Code Here

    @Test
    public void canDropIndex() {

        //given
        collection.ensureIndex("{name: 1}", "{unique: true}");
        collection.save(new Friend("John"));

        //when
        collection.dropIndex("{name: 1}");

        //then
        collection.save(new Friend("John"));
    }
View Full Code Here

TOP

Related Classes of org.jongo.model.Friend

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.